From 466999223cac8970cb78536de12d27e4b366ab8a Mon Sep 17 00:00:00 2001 From: Andis Redmans Date: Tue, 21 Oct 2025 10:29:48 +0300 Subject: [PATCH 1/3] fix: do not write specification dist tags if error is in response do not write specification dist tags if error is in response --- packages/project-access/src/project/specification.ts | 4 ++++ .../project-access/test/project/specification.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/project-access/src/project/specification.ts b/packages/project-access/src/project/specification.ts index 80b116c1398..cc59e54d2cf 100644 --- a/packages/project-access/src/project/specification.ts +++ b/packages/project-access/src/project/specification.ts @@ -107,6 +107,10 @@ export async function refreshSpecificationDistTags(options?: { logger?: Logger } logger }); const distTags = JSON.parse(distTagsString) as Record; + if ('error' in distTags) { + // Loading contains error + throw new Error(distTagsString); + } await writeFile(specificationDistTagPath, JSON.stringify(distTags, null, 4)); const uniqueVersions = new Set(Object.values(distTags)); diff --git a/packages/project-access/test/project/specification.test.ts b/packages/project-access/test/project/specification.test.ts index cb944688146..64af7002fd9 100644 --- a/packages/project-access/test/project/specification.test.ts +++ b/packages/project-access/test/project/specification.test.ts @@ -151,6 +151,16 @@ describe('Test refreshSpecificationDistTags()', () => { await refreshSpecificationDistTags({ logger }); expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('NPM_ERROR')); }); + + test('Refresh specification dist tags - error in response. Contains code and summary.', async () => { + const refreshResponse = '{"error": {"code": "ENOTFOUND", "summary": "Request to uri failed."}}'; + jest.spyOn(commandMock, 'execNpmCommand').mockResolvedValueOnce(refreshResponse); + const logger = getMockLogger(); + await refreshSpecificationDistTags({ logger }); + expect(logger.error).toHaveBeenCalledWith( + `Error refreshing specification dist-tags: Error: ${refreshResponse}` + ); + }); }); function getMockLogger(): Logger { From b22c9a10513da1829eb96fe329d0924c877f552f Mon Sep 17 00:00:00 2001 From: Andis Redmans Date: Tue, 21 Oct 2025 10:34:31 +0300 Subject: [PATCH 2/3] changelog changelog --- .changeset/itchy-seahorses-compare.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/itchy-seahorses-compare.md diff --git a/.changeset/itchy-seahorses-compare.md b/.changeset/itchy-seahorses-compare.md new file mode 100644 index 00000000000..18ba4642831 --- /dev/null +++ b/.changeset/itchy-seahorses-compare.md @@ -0,0 +1,5 @@ +--- +'@sap-ux/project-access': patch +--- + +Improve function `refreshSpecificationDistTags` - prevent caching `specification-dist-tags.json` if an error is returned in the JSON from `npm view @sap/ux-specification dist-tags --json` From 660ff49dd4a0c777290195461abe82d3f13430bc Mon Sep 17 00:00:00 2001 From: Andis Redmans Date: Tue, 21 Oct 2025 11:09:17 +0300 Subject: [PATCH 3/3] fix: comment comment --- packages/project-access/src/project/specification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/project-access/src/project/specification.ts b/packages/project-access/src/project/specification.ts index cc59e54d2cf..33ad0866909 100644 --- a/packages/project-access/src/project/specification.ts +++ b/packages/project-access/src/project/specification.ts @@ -108,7 +108,7 @@ export async function refreshSpecificationDistTags(options?: { logger?: Logger } }); const distTags = JSON.parse(distTagsString) as Record; if ('error' in distTags) { - // Loading contains error + // Abort writing cache: received error in dist-tags response throw new Error(distTagsString); } await writeFile(specificationDistTagPath, JSON.stringify(distTags, null, 4));