Skip to content

Commit

Permalink
error message added in validate changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
kanthesha committed Mar 14, 2024
1 parent e48dfe4 commit 7f2a10b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/rules/require-valid-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ describe('Rule: require-valid-changelog', () => {
});
await writeFile(
path.join(project.directoryPath, 'package.json'),
JSON.stringify({ foo: 'bar' }),
buildPackageManifestMock({ repository: {} }),
);
await writeFile(
path.join(project.directoryPath, 'CHANGELOG.md'),
invalidChangelog,
);

await expect(
validateChangelog.execute({
template: buildMetaMaskRepository(),
Expand All @@ -129,7 +128,7 @@ describe('Rule: require-valid-changelog', () => {
fail,
}),
).rejects.toThrow(
'The package does not have a well-formed manifest. This is not the fault of the changelog, but this rule requires a valid package manifest.',
'Missing `url`.\n The package does not have a well-formed manifest. This is not the fault of the changelog, but this rule requires a valid package manifest.',
);
});
});
Expand Down
14 changes: 11 additions & 3 deletions src/rules/require-valid-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import {
ChangelogFormattingError,
validateChangelog,
} from '@metamask/auto-changelog';
import { getErrorMessage, isErrorWithCode } from '@metamask/utils/node';
import {
getErrorMessage,
isErrorWithCode,
isErrorWithMessage,
} from '@metamask/utils/node';

import { buildRule } from './build-rule';
import { PackageManifestSchema, RuleName } from './types';
Expand All @@ -28,9 +32,13 @@ export default buildRule({
});
return pass();
} catch (error) {
if (isErrorWithCode(error) && error.code === 'ERR_INVALID_JSON_FILE') {
if (
isErrorWithCode(error) &&
isErrorWithMessage(error) &&
error.code === 'ERR_INVALID_JSON_FILE'
) {
throw new Error(
'The package does not have a well-formed manifest. This is not the fault of the changelog, but this rule requires a valid package manifest.',
`${error.message}\n The package does not have a well-formed manifest. This is not the fault of the changelog, but this rule requires a valid package manifest.`,
);
} else if (error instanceof ChangelogFormattingError) {
return fail([
Expand Down

0 comments on commit 7f2a10b

Please sign in to comment.