Skip to content

Commit

Permalink
Improve error message on template parsing failures
Browse files Browse the repository at this point in the history
  • Loading branch information
poveden committed Oct 10, 2019
1 parent a333f7a commit 01f633b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Update `npm` dependencies to fix:
- [WS-2019-0291](https://github.com/wycats/handlebars.js/issues/1558)

### Added

- Improve error message on template parsing failures

## [1.1.3](https://github.com/axa-group/arm-template-merge/compare/v1.1.2...v1.1.3) — 2019-09-25

### Security
Expand Down
8 changes: 7 additions & 1 deletion bin/arm-template-merge
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ async function loadTemplate(inFile) {
}

const json = jsonBuf.toString('utf8');
const template = JSON.parse(json);

let template;
try {
template = JSON.parse(json);
} catch (err) {
throw new Error(`Template '${inFile}' could not be parsed: ${err.message}`);
}

const expectedKeys = ['$schema', 'contentVersion'];

Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('CLI', () => {
rfn.mockRestore();

expect(res.exitCode).toBe(1);
expect(res.stderr).toMatch(/^Error:/);
expect(res.stderr).toMatch(/^Error: Template 'templates\/website.json' could not be parsed:/);
});

it('should be able to merge template files into a new file', async () => {
Expand Down

0 comments on commit 01f633b

Please sign in to comment.