How to make a Gatsby build terminate on error
![Oscar de la Hera Gomez](https://www.delasign.com/CDN/headshots/profile.webp)
![A flower that represents Gatsby with the text 'Terminate Build' beneath it.](https://www.delasign.com/CDN/images/How-to-make-a-Gatsby-build-terminate-on-error.webp)
To cancel, end or terminate a Gatsby build call the GatsbyReporter panic function.
![A screenshot of Terminal showing that the Gatsby build continues even if create pages succeeds.](https://www.delasign.com/CDN/images/Error.webp)
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
![A screenshot of Terminal showing the build failing with an error and terminating the build.](https://www.delasign.com/CDN/images/Result.webp)
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 inquiries@delasign.com with any thoughts or feedback you may have.