Skip to content

Commit 2b12667

Browse files
lesya7cursoragent
andcommitted
fix: precise error messages for dist fallback (missing folder, missing file, empty file)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9ddd974 commit 2b12667

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/resolve/adapters/webApplicationsSourceAdapter.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,23 @@ export class WebApplicationsSourceAdapter extends BundleSourceAdapter {
9292
const distPath = join(contentPath, 'dist');
9393
const indexPath = join(distPath, 'index.html');
9494

95-
const missingDistIndexMessage =
96-
"If a webapplication.json file does not exist, you are required to include a 'dist/index.html' file. This will be the entry point for your web application.";
97-
9895
if (!this.tree.exists(distPath) || !this.tree.isDirectory(distPath)) {
99-
throw new SfError(missingDistIndexMessage, 'ExpectedSourceFilesError');
96+
throw new SfError(
97+
"When webapplication.json is not present, a 'dist' folder containing 'index.html' is required. The 'dist' folder was not found.",
98+
'ExpectedSourceFilesError'
99+
);
100100
}
101101
if (!this.tree.exists(indexPath)) {
102-
throw new SfError(missingDistIndexMessage, 'ExpectedSourceFilesError');
102+
throw new SfError(
103+
"When webapplication.json is not present, a 'dist/index.html' file is required as the entry point. The file was not found.",
104+
'ExpectedSourceFilesError'
105+
);
103106
}
104107
if (this.tree.readFileSync(indexPath).length === 0) {
105-
throw new SfError(missingDistIndexMessage, 'ExpectedSourceFilesError');
108+
throw new SfError(
109+
"When webapplication.json is not present, 'dist/index.html' must exist and be non-empty. The file was found but is empty.",
110+
'ExpectedSourceFilesError'
111+
);
106112
}
107113
}
108114

test/resolve/adapters/webApplicationsSourceAdapter.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ describe('WebApplicationsSourceAdapter', () => {
113113
expect(metadataAdapter.getComponent(META_FILE, false)).to.deep.equal(expected);
114114
});
115115

116-
const DIST_INDEX_MESSAGE =
117-
"If a webapplication.json file does not exist, you are required to include a 'dist/index.html' file. This will be the entry point for your web application.";
118-
119116
describe('without webapplication.json (dist fallback)', () => {
120117
it('should throw when the dist folder does not exist', () => {
121118
const t = VirtualTreeContainer.fromFilePaths([META_FILE, CONTENT_FILE]);
122119
const a = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t);
123-
assert.throws(() => a.getComponent(APP_PATH), SfError, DIST_INDEX_MESSAGE);
120+
assert.throws(
121+
() => a.getComponent(APP_PATH),
122+
SfError,
123+
"When webapplication.json is not present, a 'dist' folder containing 'index.html' is required. The 'dist' folder was not found."
124+
);
124125
});
125126

126127
it('should throw when dist exists but index.html is missing', () => {
@@ -130,7 +131,11 @@ describe('WebApplicationsSourceAdapter', () => {
130131
];
131132
const t = new VirtualTreeContainer(vfs);
132133
const a = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t);
133-
assert.throws(() => a.getComponent(APP_PATH), SfError, DIST_INDEX_MESSAGE);
134+
assert.throws(
135+
() => a.getComponent(APP_PATH),
136+
SfError,
137+
"When webapplication.json is not present, a 'dist/index.html' file is required as the entry point. The file was not found."
138+
);
134139
});
135140

136141
it('should throw when dist/index.html is empty', () => {
@@ -140,7 +145,11 @@ describe('WebApplicationsSourceAdapter', () => {
140145
];
141146
const t = new VirtualTreeContainer(vfs);
142147
const a = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t);
143-
assert.throws(() => a.getComponent(APP_PATH), SfError, DIST_INDEX_MESSAGE);
148+
assert.throws(
149+
() => a.getComponent(APP_PATH),
150+
SfError,
151+
"When webapplication.json is not present, 'dist/index.html' must exist and be non-empty. The file was found but is empty."
152+
);
144153
});
145154

146155
it('should succeed when dist/index.html exists and is non-empty', () => {

0 commit comments

Comments
 (0)