Skip to content

Commit

Permalink
chore: Minor tweaks to the messages logged for JSON parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl committed Sep 27, 2019
1 parent a44e350 commit 155bdfa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export async function getDefaultLocalizedName(
messageContents = stripBom(messageContents);

try {
messageData = parseJSON(stripJsonComments(messageContents), messageFile);
messageData = parseJSON(stripJsonComments(messageContents));
} catch (error) {
throw new UsageError(
`Error parsing messages.json ${error}`);
`Error parsing messages.json file at ${messageFile}: ${error}`);
}

extensionName = manifestData.name.replace(
Expand Down
4 changes: 2 additions & 2 deletions src/util/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export default async function getValidatedManifest(
let manifestData;

try {
manifestData = parseJSON(stripJsonComments(manifestContents), manifestFile);
manifestData = parseJSON(stripJsonComments(manifestContents));
} catch (error) {
throw new InvalidManifest(
`Error parsing manifest.json at ${manifestFile}: ${error}`);
`Error parsing manifest.json file at ${manifestFile}: ${error}`);
}

const errors = [];
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/test-util/test.manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@ describe('util/manifest', () => {
it('reports an error for invalid manifest JSON', () => withTempDir(
(tmpDir) => {
const badManifest = `{
"name": "I'm an invalid JSON Manifest
"name": "I'm an invalid JSON Manifest",,
"version": "0.0.0"
}`;
const manifestFile = path.join(tmpDir.path(), 'manifest.json');
return fs.writeFile(manifestFile, badManifest)
.then(() => getValidatedManifest(tmpDir.path()))
.then(makeSureItFails())
.catch(onlyInstancesOf(InvalidManifest, (error) => {
assert.match(error.message, /Error parsing manifest\.json at /);
assert.match(
error.message,
/Error parsing manifest\.json file at /
);
assert.include(
error.message, 'Unexpected token in JSON at position 49');
error.message,
'Unexpected token , in JSON at position 51'
);
assert.include(error.message, manifestFile);
}));
}
Expand Down Expand Up @@ -195,8 +200,10 @@ describe('util/manifest', () => {
const promise = getValidatedManifest(tmpDir.path());

const error = await assert.isRejected(promise, InvalidManifest);
await assert.isRejected(promise, /Error parsing manifest\.json at /);
assert.include(error.message, 'in JSON at position 133');
await assert.isRejected(
promise,
/Error parsing manifest\.json file at .* in JSON at position 133/
);
assert.include(error.message, manifestFile);
})
);
Expand Down

0 comments on commit 155bdfa

Please sign in to comment.