From f97dc4ebd6d8fa01b5908148957e72359a6f2942 Mon Sep 17 00:00:00 2001 From: Ryan Haskell-Glatz Date: Sat, 8 May 2021 12:16:06 -0500 Subject: [PATCH] handle invalid elm.json error --- src/cli/src/cli/build.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cli/src/cli/build.ts b/src/cli/src/cli/build.ts index 3cb925e..ca3d5b0 100644 --- a/src/cli/src/cli/build.ts +++ b/src/cli/src/cli/build.ts @@ -195,7 +195,21 @@ const compileMainElm = (env: Environment) => async () => { }) } - type ElmError = { + type ElmError + = ElmCompileError + | ElmJsonError + + type ElmCompileError = { + type: 'compile-errors' + errors: ElmProblemError[] + } + + type ElmJsonError = Problem & { + type: 'error', + path: string, + } + + type ElmProblemError = { path: string problems: Problem[] } @@ -212,9 +226,11 @@ const compileMainElm = (env: Environment) => async () => { string: string } - const colorElmError = (output : { errors: ElmError[] }) => { - - const { errors } = output + const colorElmError = (output : ElmError) => { + const errors : ElmProblemError[] = + output.type === 'compile-errors' + ? output.errors + : [ { path: output.path, problems: [output] } ] const strIf = (str: string) => (cond: boolean): string => cond ? str : '' const boldIf = strIf(bold) @@ -222,7 +238,7 @@ const compileMainElm = (env: Environment) => async () => { const repeat = (str: string, num: number, min = 3) => [...Array(num < 0 ? min : num)].map(_ => str).join('') - const errorToString = (error: ElmError): string => { + const errorToString = (error: ElmProblemError): string => { const problemToString = (problem: Problem): string => { const path = error.path.substr(process.cwd().length + 1) return [