Failed during stage 'building site': Build script returned non-zero exit code: 2

I’m having trouble trying to identify where the fatal error may be:

7:48:33 PM: Build ready to start
7:48:35 PM: build-image version: 9cade8af58c2cf3a17a1e9433d2e979149488837
7:48:35 PM: build-image tag: v3.3.5
7:48:35 PM: buildbot version: eb060c4dc3a8a73f9004f460f04632708166ca51
7:48:35 PM: Fetching cached dependencies
7:48:35 PM: Starting to download cache of 110.1MB
7:48:35 PM: Finished downloading cache in 683.546958ms
7:48:35 PM: Starting to extract cache
7:48:38 PM: Finished extracting cache in 3.028168619s
7:48:38 PM: Finished fetching cache in 3.808335948s
7:48:38 PM: Starting to prepare the repo for build
7:48:39 PM: Preparing Git Reference refs/heads/master
7:48:46 PM: Found Netlify configuration file. Overriding site configuration
7:48:46 PM: Starting build script
7:48:46 PM: Installing dependencies
7:48:47 PM: Started restoring cached node version
7:48:49 PM: Finished restoring cached node version
7:48:50 PM: Downloading and installing node v10.17.0…
7:48:50 PM: Computing checksum with sha256sum
7:48:51 PM: Checksums matched!
7:48:52 PM: Attempting ruby version 2.6.2, read from environment
7:48:54 PM: Using ruby version 2.6.2
7:48:54 PM: Using PHP version 5.6
7:48:54 PM: Installing Hugo 0.58.3
7:48:54 PM: Hugo Static Site Generator v0.58.3-4AAC02D4/extended linux/amd64 BuildDate: 2019-09-19T15:34:54Z
7:48:54 PM: Started restoring cached go cache
7:48:55 PM: Finished restoring cached go cache
7:48:55 PM: unset GOOS;
7:48:55 PM: unset GOARCH;
7:48:55 PM: export GOROOT=’/opt/buildhome/.gimme/versions/go1.12.linux.amd64’;
7:48:55 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
7:48:55 PM: go version >&2;
7:48:55 PM: export GIMME_ENV=’/opt/buildhome/.gimme/env/go1.12.linux.amd64.env’;
7:48:55 PM: go version go1.12 linux/amd64
7:48:55 PM: Installing missing commands
7:48:55 PM: Verify run directory
7:48:55 PM: Executing user command: hugo --gc --minify -b $URL
7:48:55 PM: Building sites …
7:48:56 PM: panic: parse /post/Icon
: net/url: invalid control character in URL
7:48:56 PM: goroutine 86 [running]:
… ### Couldn’t keep all the links of goroutine in this post.
7:48:56 PM: Skipping functions preparation step: no functions directory set
7:48:56 PM: Caching artifacts
7:48:56 PM: Started saving pip cache
7:48:56 PM: Finished saving pip cache
7:48:56 PM: Started saving emacs cask dependencies
7:48:56 PM: Finished saving emacs cask dependencies
7:48:56 PM: Started saving maven dependencies
7:48:56 PM: Finished saving maven dependencies
7:48:56 PM: Started saving boot dependencies
7:48:56 PM: Finished saving boot dependencies
7:48:56 PM: Started saving go dependencies
7:48:56 PM: Finished saving go dependencies
7:49:00 PM: Error running command: Build script returned non-zero exit code: 2
7:49:00 PM: Failing build: Failed to build site
7:49:00 PM: failed during stage ‘building site’: Build script returned non-zero exit code: 2
7:49:00 PM: Finished processing build request in 25.547765543s

Seems like it’s right here:

I’ve never seen that before, but it is quite possible that you’re running out of memory - not sure how many pages you have or what settings you use in hugo. You might try hugo -vvv --gc -minify -b $URL to be more verbose, and then maybe you can see where it’s hanging. You should also try running locally in only 3Gb of memory to simulate our build env and you may find the same behavior on your own dev env…