Nuxt.js: `nuxt generate` should exit with non-zero code on errors

Created on 8 Feb 2019  路  7Comments  路  Source: nuxt/nuxt.js

Version

v2.4.3

Reproduction link

https://github.com/njam/nuxt-generate-error

Steps to reproduce

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 $?

What is expected ?

Should exit with a code higher than 0.

What is actually happening?

Exits with code 0.

Additional comments?

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}`)
  })
}

This bug report is available on Nuxt community (#c8629)
bug-report pending

Most helpful comment

I can confirm that the new --fail-on-error flag fixes this.
Thanks @loomchild, much appreciated!

All 7 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

surmon-china picture surmon-china  路  3Comments

gary149 picture gary149  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

uptownhr picture uptownhr  路  3Comments