Skip to content

Commit

Permalink
Add filename when in handlebars errors (#407)
Browse files Browse the repository at this point in the history
@posva nice!
  • Loading branch information
posva authored and zigomir committed Mar 20, 2017
1 parent c8801b6 commit 439aece
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ function renderTemplateFiles (skipInterpolation) {
return next()
}
render(str, metalsmithMetadata, function (err, res) {
if (err) return next(err)
if (err) {
err.message = `[${file}] ${err.message}`
return next(err)
}
files[file].contents = new Buffer(res)
next()
})
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/mock-error/meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
prompts: {
name: {
type: 'string',
required: true,
message: 'Name'
}
}
}
1 change: 1 addition & 0 deletions test/e2e/mock-error/template/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{error,name}}
9 changes: 9 additions & 0 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const MOCK_TEMPLATE_REPO_PATH = path.resolve('./test/e2e/mock-template-repo')
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')
const MOCK_METADATA_REPO_JS_PATH = path.resolve('./test/e2e/mock-metadata-repo-js')
const MOCK_SKIP_GLOB = path.resolve('./test/e2e/mock-skip-glob')
const MOCK_ERROR = path.resolve('./test/e2e/mock-error')

function monkeyPatchInquirer (answers) {
// monkey patch inquirer
Expand Down Expand Up @@ -223,4 +224,12 @@ describe('vue-cli', () => {
expect(getTemplatePath('..')).to.equal(path.join(__dirname, '/../../..'))
expect(getTemplatePath('../template')).to.equal(path.join(__dirname, '/../../../template'))
})

it.only('points out the file in the error', done => {
monkeyPatchInquirer(answers)
generate('test', MOCK_ERROR, MOCK_TEMPLATE_BUILD_PATH, err => {
expect(err.message).to.match(/^\[readme\.md\] Parse error/)
done()
})
})
})

0 comments on commit 439aece

Please sign in to comment.