Catch "empty" site builds and throw error (Gatsby)

Hi,

I have the problem, that sometimes my websites build an empty page and only show the “Page Not Found” page. Once downloaded the app., it is only consisting of a netlify.toml file – nothing else.

I guess this happens because the creation of pages wasn’t successful. But the site is auto-published anyways.

It would be great, if a build only shows a “Page Not Found” page, the build would throw an error and wouldn’t get published.

Or is there an easy way to catch an empty website, so I could throw an error manually?

I am using Gatsby with:

  • gatsby-source-wordpress-experimental v. ^2.0.1
  • gatsby-plugin-netlify-cache v. ^1.2.0 - idk if that matters.

If it’s empty, sure, you could update your build command to include a little bash script that checks if something like index.html is present, or maybe even the ignore build option in netlify.toml.

Sounds like you have some digging to do, in order to work out why the build sometimes outputs blanks! :slight_smile:

1 Like

Thanks for the fast answer @Scott .

Sorry I am quite clueless about this stuff.
So in netlify.toml something like this?

[build]
  FILE=/index.html
  if test -f "$FILE"; then
    ignore = "git diff --quiet HEAD^ HEAD sub_dir/"
  fi

Anyone, who can help with this?

You can try using some Node Modules like file-exists - npm to check if file exists using onPostBuild (maybe) and if it doesn’t exist, use another module to throw an error (and possibly cancel the build): throw-error - npm.

1 Like

Thanks will try that!

1 Like