Skip to content

Add filename when in handlebars errors #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
})