Skip to content

Commit 0017132

Browse files
lesya7cursoragent
andcommitted
fix: custom error messages for rewrites (include path), full invalid JSON test
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 68a8f79 commit 0017132

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/resolve/adapters/webApplicationsSourceAdapter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ export class WebApplicationsSourceAdapter extends BundleSourceAdapter {
167167
if (rewrite) {
168168
const rewritePath = join(outputDirPath, stripLeadingSep(rewrite));
169169
if (!this.tree.exists(rewritePath)) {
170-
this.expectedSourceError(rewritePath);
170+
throw new SfError(
171+
`A rewrite target defined in webapplication.json -> routing.rewrites was not found: ${rewritePath}. Ensure the file exists at that location.`,
172+
'ExpectedSourceFilesError'
173+
);
171174
}
172175
}
173176
}

test/resolve/adapters/webApplicationsSourceAdapter.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('WebApplicationsSourceAdapter', () => {
214214
);
215215
};
216216

217-
it('should throw on malformed JSON', () => {
217+
it('should throw on malformed JSON with full error detail', () => {
218218
const vfs: VirtualDirectory[] = [
219219
{
220220
dirPath: APP_PATH,
@@ -230,7 +230,11 @@ describe('WebApplicationsSourceAdapter', () => {
230230
forceIgnore,
231231
new VirtualTreeContainer(vfs)
232232
);
233-
assert.throws(() => a.getComponent(APP_PATH), SfError, 'Invalid JSON in webapplication.json');
233+
assert.throws(
234+
() => a.getComponent(APP_PATH),
235+
SfError,
236+
/^Invalid JSON in webapplication\.json: .+/
237+
);
234238
});
235239

236240
it('should throw when outputDir is missing', () => {
@@ -306,13 +310,11 @@ describe('WebApplicationsSourceAdapter', () => {
306310
const a = adapterWith(config, [
307311
{ dirPath: DIST_PATH, children: [{ name: 'index.html', data: Buffer.from('<html>test</html>') }] },
308312
]);
313+
const expectedPath = join(DIST_PATH, 'missing-rewrite.html');
309314
assert.throws(
310315
() => a.getComponent(APP_PATH),
311316
SfError,
312-
messages.getMessage('error_expected_source_files', [
313-
join(DIST_PATH, 'missing-rewrite.html'),
314-
registry.types.webapplication.name,
315-
])
317+
`A rewrite target defined in webapplication.json -> routing.rewrites was not found: ${expectedPath}. Ensure the file exists at that location.`
316318
);
317319
});
318320

@@ -414,13 +416,11 @@ describe('WebApplicationsSourceAdapter', () => {
414416
],
415417
};
416418
const a = adapterWith(config, [distDir]);
419+
const expectedPath = join(DIST_PATH, 'missing-docs.html');
417420
assert.throws(
418421
() => a.getComponent(APP_PATH),
419422
SfError,
420-
messages.getMessage('error_expected_source_files', [
421-
join(DIST_PATH, 'missing-docs.html'),
422-
registry.types.webapplication.name,
423-
])
423+
`A rewrite target defined in webapplication.json -> routing.rewrites was not found: ${expectedPath}. Ensure the file exists at that location.`
424424
);
425425
});
426426
});

0 commit comments

Comments
 (0)