diff --git a/src/cli/src/cli/build.ts b/src/cli/src/cli/build.ts index 16fd4bb..d8f72a5 100644 --- a/src/cli/src/cli/build.ts +++ b/src/cli/src/cli/build.ts @@ -137,8 +137,23 @@ const compileMainElm = (env : Environment) => async () => { .catch(colorElmError) } + const red = colors.RED + const green = colors.green + const colorElmError = (err : string) => { - const errors = JSON.parse(err).errors as Error[] || [] + let errors = [] + + try { + errors = JSON.parse(err).errors as Error[] || [] + } catch (e) { + return Promise.reject([ + `${red}Something went wrong with elm-spa.${reset}`, + `Please report this entire error to ${green}https://github.com/ryannhg/elm-spa/issues${reset}`, + `-----`, + err, + `-----` + ].join('\n\n')) + } const strIf = (str : string) => (cond : boolean) : string => cond ? str : '' const boldIf = strIf(bold) diff --git a/src/cli/src/process.ts b/src/cli/src/process.ts index 3f70816..08018de 100644 --- a/src/cli/src/process.ts +++ b/src/cli/src/process.ts @@ -2,5 +2,8 @@ import { exec } from 'child_process' export const run = (cmd : string) : Promise => new Promise((resolve, reject) => - exec(cmd, (err, stdout, stderr) => err ? reject(stderr) : resolve(stdout)) + exec(cmd, (err, stdout, stderr) => err + ? reject(stderr.split('npm ERR!')[0] || stderr) + : resolve(stdout) + ) ) \ No newline at end of file