Skip to content

Commit 6dfeb9c

Browse files
authored
Ensure empty extended config throws a diagnostic (#9701)
* Ensure empty extended config throws a diagnostic * Fix linting issue
1 parent 59ed066 commit 6dfeb9c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/core/core/src/requests/ParcelConfigRequest.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import ThrowableDiagnostic, {
2727
generateJSONCodeHighlights,
2828
escapeMarkdown,
2929
md,
30+
errorToDiagnostic,
3031
} from '@parcel/diagnostic';
3132
import {parse} from 'json5';
3233
import path from 'path';
@@ -467,7 +468,7 @@ export async function processConfigChain(
467468

468469
if (errors.length > 0) {
469470
throw new ThrowableDiagnostic({
470-
diagnostic: errors.flatMap(e => e.diagnostics),
471+
diagnostic: errors.flatMap(e => e.diagnostics ?? errorToDiagnostic(e)),
471472
});
472473
}
473474
}
@@ -574,7 +575,16 @@ export function validateConfigFile(
574575
config: RawParcelConfig | ResolvedParcelConfigFile,
575576
relativePath: FilePath,
576577
) {
577-
validateNotEmpty(config, relativePath);
578+
try {
579+
validateNotEmpty(config, relativePath);
580+
} catch (e) {
581+
throw new ThrowableDiagnostic({
582+
diagnostic: {
583+
message: e.message,
584+
origin: '@parcel/core',
585+
},
586+
});
587+
}
578588

579589
validateSchema.diagnostic(
580590
ParcelConfigSchema,

packages/core/core/test/ParcelConfigRequest.test.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,12 @@ describe('ParcelConfigRequest', () => {
309309
});
310310

311311
it('should throw error on empty config file', () => {
312-
assert.throws(() => {
313-
validateConfigFile({}, '.parcelrc');
314-
}, /.parcelrc can't be empty/);
312+
assert.throws(
313+
() => {
314+
validateConfigFile({}, '.parcelrc');
315+
},
316+
{name: 'Error', message: ".parcelrc can't be empty"},
317+
);
315318
});
316319
});
317320

0 commit comments

Comments
 (0)