build.js: improve error handling