Skip to content

Commit

Permalink
Ensure empty extended config throws a diagnostic (#9701)
Browse files Browse the repository at this point in the history
* Ensure empty extended config throws a diagnostic

* Fix linting issue
  • Loading branch information
marcins committed May 7, 2024
1 parent 59ed066 commit 6dfeb9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions packages/core/core/src/requests/ParcelConfigRequest.js
Expand Up @@ -27,6 +27,7 @@ import ThrowableDiagnostic, {
generateJSONCodeHighlights,
escapeMarkdown,
md,
errorToDiagnostic,
} from '@parcel/diagnostic';
import {parse} from 'json5';
import path from 'path';
Expand Down Expand Up @@ -467,7 +468,7 @@ export async function processConfigChain(

if (errors.length > 0) {
throw new ThrowableDiagnostic({
diagnostic: errors.flatMap(e => e.diagnostics),
diagnostic: errors.flatMap(e => e.diagnostics ?? errorToDiagnostic(e)),
});
}
}
Expand Down Expand Up @@ -574,7 +575,16 @@ export function validateConfigFile(
config: RawParcelConfig | ResolvedParcelConfigFile,
relativePath: FilePath,
) {
validateNotEmpty(config, relativePath);
try {
validateNotEmpty(config, relativePath);
} catch (e) {
throw new ThrowableDiagnostic({
diagnostic: {
message: e.message,
origin: '@parcel/core',
},
});
}

validateSchema.diagnostic(
ParcelConfigSchema,
Expand Down
9 changes: 6 additions & 3 deletions packages/core/core/test/ParcelConfigRequest.test.js
Expand Up @@ -309,9 +309,12 @@ describe('ParcelConfigRequest', () => {
});

it('should throw error on empty config file', () => {
assert.throws(() => {
validateConfigFile({}, '.parcelrc');
}, /.parcelrc can't be empty/);
assert.throws(
() => {
validateConfigFile({}, '.parcelrc');
},
{name: 'Error', message: ".parcelrc can't be empty"},
);
});
});

Expand Down

0 comments on commit 6dfeb9c

Please sign in to comment.