https://github.com/njam/nuxt-generate-error
If an exception is thrown during rendering of a page in nuxt generate
, this error is printed, but still the script exits with status 0. For both handled and unhandled errors. This is especially problematic in CI, as unhandled errors go unnoticed.
The repo to reproduce the error just throws an error in created()
:
created() {
throw new Error("My error");
}
Clone repo to reproduce:
git clone [email protected]:njam/nuxt-generate-error.git
cd nuxt-generate-error
yarn install
yarn run generate
echo $?
Should exit with a code higher than 0.
Exits with code 0.
As a workaround I'm currently registering a modules like this:
export default function() {
this.nuxt.hook('generate:routeFailed', ({ route, errors }) => {
let error = errors[0].error
throw new Error(`Error generating ${route}:\n${error}`)
})
}
As mentioned in https://github.com/nuxt-community/nuxt-generate-cluster/pull/17 this behaviour should always be configurable. There are many valid reasons why you still could want to continue on unhandled page errors (eg time constraints by pressing clients who want you to publish YESTERDAY and not now or tomorrow).
Changing this behaviour is a breaking change.
Would it be a good idea to add --fail-on-error
option to standard nuxt generate
(I can propose a PR perhaps)? Or shall I simply use nuxt-generate-cluster
as it will replace standard nuxt-generate
at some point?
+1 for --fail-on-error
option. Implement would be straight forward :)
@loomchild nuxt-generate will never replace the standard generate. Hopefully nuxt will support multiple generate workers by default in the future so nuxt-generate-cluster becomes obsolete :)
I would recommend to name the option --fail-on-page-error
as just error might be a bit generic and if failing ever becomes the default it would be strange to use --no-fail-on-error
to only skip page errors (and imo you want to differentiate between page errors and other errors). At least that was my reasoning with nuxt-generate-cluster.
Give me few days and I will propose PR. Implementation itself seems to not be very hard, but I don't know the codebase, process how to test a development version and how do you write automated tests in the project yet.
Implemented in #5195 by @loomchild
I can confirm that the new --fail-on-error
flag fixes this.
Thanks @loomchild, much appreciated!
Most helpful comment
I can confirm that the new
--fail-on-error
flag fixes this.Thanks @loomchild, much appreciated!