mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-12 03:38:07 +00:00
Merge pull request #662 from jroxendal/generate-error-report
[Feature] generate error report
This commit is contained in:
commit
71c9838008
@ -41,6 +41,7 @@ const defaults = {
|
|||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const s = Date.now()
|
const s = Date.now()
|
||||||
|
let errors = []
|
||||||
/*
|
/*
|
||||||
** Set variables
|
** Set variables
|
||||||
*/
|
*/
|
||||||
@ -97,14 +98,29 @@ export default function () {
|
|||||||
yield routes.splice(0, 500).map((route) => {
|
yield routes.splice(0, 500).map((route) => {
|
||||||
return co(function * () {
|
return co(function * () {
|
||||||
yield waitFor(n++ * self.options.generate.interval)
|
yield waitFor(n++ * self.options.generate.interval)
|
||||||
var { html } = yield self.renderRoute(route, { _generate: true })
|
try {
|
||||||
html = minify(html, self.options.generate.minify)
|
var { html, error } = yield self.renderRoute(route, { _generate: true })
|
||||||
|
if(error) {
|
||||||
|
errors.push({type : "handled", route, error})
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
errors.push({type : "unhandled", route, error : err})
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var minifiedHtml = minify(html, self.options.generate.minify)
|
||||||
|
} catch(err) {
|
||||||
|
let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`)
|
||||||
|
errors.push({type : "unhandled", route, error : minifyErr})
|
||||||
|
return
|
||||||
|
}
|
||||||
var path = join(route, sep, 'index.html') // /about -> /about/index.html
|
var path = join(route, sep, 'index.html') // /about -> /about/index.html
|
||||||
debug('Generate file: ' + path)
|
debug('Generate file: ' + path)
|
||||||
path = join(distPath, path)
|
path = join(distPath, path)
|
||||||
// Make sure the sub folders are created
|
// Make sure the sub folders are created
|
||||||
yield mkdirp(dirname(path))
|
yield mkdirp(dirname(path))
|
||||||
yield writeFile(path, html, 'utf8')
|
yield writeFile(path, minifiedHtml, 'utf8')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -119,6 +135,17 @@ export default function () {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
const duration = Math.round((Date.now() - s) / 100) / 10
|
const duration = Math.round((Date.now() - s) / 100) / 10
|
||||||
debug(`HTML Files generated in ${duration}s`)
|
debug(`HTML Files generated in ${duration}s`)
|
||||||
|
|
||||||
|
if(errors.length) {
|
||||||
|
console.error("==== Error report ==== \n" + errors.map( ({type, route, error}) => {
|
||||||
|
if(type == "unhandled") {
|
||||||
|
return `Route: '${route}'\n${error.stack}`
|
||||||
|
} else {
|
||||||
|
return `Route: '${route}' returned an error via context.error: \n` +
|
||||||
|
JSON.stringify(error)
|
||||||
|
}
|
||||||
|
}).join("\n\n"))
|
||||||
|
}
|
||||||
return this
|
return this
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user