How to make a Gatsby build terminate on error
To cancel, end or terminate a Gatsby build call the GatsbyReporter panic function.
An example of create pages having failed but the build continued anyway.
During our time using Gatsby we noticed that builds keep running even if they fail - for example, if a GraphQL query takes longer than it should on the backend.
This implies that, under this mode of operation, you could release a broken or incomplete site.
So how do you make a build exit or cancel, if something goes wrong during the build process?
Use GatsbyReporter's panic function
GatsbyJS's node functionality includes a reporter known as GatsbyReporter which offers various functions including:
- panic: which cancels a build and prints an error
- panicOnBuild: which prints an error but does not cancel a build.
To see it in use, check out the gist below:
Any Questions ?
We are actively looking for feedback on how to improve this resource. Please send us a note to firstname.lastname@example.org with any thoughts or feedback you may have.