Skip to content

Commit 68843d7

Browse files
lesya7cursoragent
andcommitted
fix: provide specific error messages for missing webapplication.json fields
Address code review feedback: error messages now explicitly state which required field is missing (outputDir, routing, routing.trailingSlash, routing.fallback) instead of generic 'Expected source files' message. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 32245c5 commit 68843d7

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/resolve/adapters/webApplicationsSourceAdapter.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,30 @@ export class WebApplicationsSourceAdapter extends BundleSourceAdapter {
115115
}
116116

117117
if (!config.outputDir || typeof config.outputDir !== 'string') {
118-
this.expectedSourceError(descriptorPath);
118+
throw new SfError(
119+
"webapplication.json is missing required field 'outputDir'",
120+
'InvalidWebApplicationConfigError'
121+
);
119122
}
120123
const outputDirPath = join(contentPath, config.outputDir);
121124
if (!this.tree.exists(outputDirPath) || !this.tree.isDirectory(outputDirPath)) {
122125
this.expectedSourceError(outputDirPath);
123126
}
124127

125128
if (!config.routing || typeof config.routing !== 'object') {
126-
this.expectedSourceError(descriptorPath);
129+
throw new SfError("webapplication.json is missing required field 'routing'", 'InvalidWebApplicationConfigError');
127130
}
128131
if (!config.routing.trailingSlash || typeof config.routing.trailingSlash !== 'string') {
129-
this.expectedSourceError(descriptorPath);
132+
throw new SfError(
133+
"webapplication.json is missing required field 'routing.trailingSlash'",
134+
'InvalidWebApplicationConfigError'
135+
);
130136
}
131137
if (!config.routing.fallback || typeof config.routing.fallback !== 'string') {
132-
this.expectedSourceError(descriptorPath);
138+
throw new SfError(
139+
"webapplication.json is missing required field 'routing.fallback'",
140+
'InvalidWebApplicationConfigError'
141+
);
133142
}
134143

135144
const fallbackPath = join(outputDirPath, config.routing.fallback.replace(/^\//, ''));

test/resolve/adapters/webApplicationsSourceAdapter.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ describe('WebApplicationsSourceAdapter', () => {
244244
assert.throws(
245245
() => a.getComponent(APP_PATH),
246246
SfError,
247-
messages.getMessage('error_expected_source_files', [JSON_FILE, registry.types.webapplication.name])
247+
"webapplication.json is missing required field 'outputDir'"
248248
);
249249
});
250250

@@ -264,11 +264,7 @@ describe('WebApplicationsSourceAdapter', () => {
264264
const a = adapterWith({ outputDir: 'dist' }, [
265265
{ dirPath: DIST_PATH, children: [{ name: 'index.html', data: Buffer.from('<html>test</html>') }] },
266266
]);
267-
assert.throws(
268-
() => a.getComponent(APP_PATH),
269-
SfError,
270-
messages.getMessage('error_expected_source_files', [JSON_FILE, registry.types.webapplication.name])
271-
);
267+
assert.throws(() => a.getComponent(APP_PATH), SfError, "webapplication.json is missing required field 'routing'");
272268
});
273269

274270
it('should throw when routing.fallback is missing', () => {
@@ -278,7 +274,7 @@ describe('WebApplicationsSourceAdapter', () => {
278274
assert.throws(
279275
() => a.getComponent(APP_PATH),
280276
SfError,
281-
messages.getMessage('error_expected_source_files', [JSON_FILE, registry.types.webapplication.name])
277+
"webapplication.json is missing required field 'routing.fallback'"
282278
);
283279
});
284280

@@ -289,7 +285,7 @@ describe('WebApplicationsSourceAdapter', () => {
289285
assert.throws(
290286
() => a.getComponent(APP_PATH),
291287
SfError,
292-
messages.getMessage('error_expected_source_files', [JSON_FILE, registry.types.webapplication.name])
288+
"webapplication.json is missing required field 'routing.trailingSlash'"
293289
);
294290
});
295291

0 commit comments

Comments
 (0)