Skip to content

Commit 439aece

Browse files
posvazigomir
authored andcommitted
Add filename when in handlebars errors (vuejs#407)
@posva nice!
1 parent c8801b6 commit 439aece

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

lib/generate.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ function renderTemplateFiles (skipInterpolation) {
115115
return next()
116116
}
117117
render(str, metalsmithMetadata, function (err, res) {
118-
if (err) return next(err)
118+
if (err) {
119+
err.message = `[${file}] ${err.message}`
120+
return next(err)
121+
}
119122
files[file].contents = new Buffer(res)
120123
next()
121124
})

test/e2e/mock-error/meta.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
prompts: {
3+
name: {
4+
type: 'string',
5+
required: true,
6+
message: 'Name'
7+
}
8+
}
9+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{error,name}}

test/e2e/test.js

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const MOCK_TEMPLATE_REPO_PATH = path.resolve('./test/e2e/mock-template-repo')
1717
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')
1818
const MOCK_METADATA_REPO_JS_PATH = path.resolve('./test/e2e/mock-metadata-repo-js')
1919
const MOCK_SKIP_GLOB = path.resolve('./test/e2e/mock-skip-glob')
20+
const MOCK_ERROR = path.resolve('./test/e2e/mock-error')
2021

2122
function monkeyPatchInquirer (answers) {
2223
// monkey patch inquirer
@@ -223,4 +224,12 @@ describe('vue-cli', () => {
223224
expect(getTemplatePath('..')).to.equal(path.join(__dirname, '/../../..'))
224225
expect(getTemplatePath('../template')).to.equal(path.join(__dirname, '/../../../template'))
225226
})
227+
228+
it.only('points out the file in the error', done => {
229+
monkeyPatchInquirer(answers)
230+
generate('test', MOCK_ERROR, MOCK_TEMPLATE_BUILD_PATH, err => {
231+
expect(err.message).to.match(/^\[readme\.md\] Parse error/)
232+
done()
233+
})
234+
})
226235
})

0 commit comments

Comments
 (0)