diff --git a/cli/elm.json b/cli/elm.json index 54b1676..fe17b5d 100644 --- a/cli/elm.json +++ b/cli/elm.json @@ -7,12 +7,12 @@ "elm-version": "0.19.1", "dependencies": { "direct": { - "MaybeJustJames/yaml": "2.1.7", "dillonkearns/elm-cli-options-parser": "5.0.1", "dillonkearns/elm-pages": "12.2.1", "elm/bytes": "1.0.8", "elm/core": "1.0.5", "elm/json": "1.1.4", + "elm/parser": "1.1.0", "elm/regex": "1.0.0", "elm/url": "1.0.0", "elmcraft/core-extra": "2.3.0", @@ -20,6 +20,9 @@ "json-tools/json-value": "1.0.1", "mdgriffith/elm-codegen": "6.0.3", "miniBill/elm-fast-dict": "1.2.6", + "miniBill/elm-parser-error-extra": "1.0.1", + "miniBill/elm-yaml": "1.0.0", + "pithub/elm-parser-bug-workaround": "1.0.0", "robinheghan/murmur3": "1.0.0", "the-sett/elm-pretty-printer": "3.3.1", "wolfadex/elm-ansi": "3.0.1", @@ -28,6 +31,7 @@ "indirect": { "BrianHicks/elm-string-graphemes": "1.0.4", "Chadtech/elm-bool-extra": "2.4.2", + "MaybeJustJames/yaml": "2.1.7", "NoRedInk/elm-json-decode-pipeline": "1.0.1", "avh4/elm-color": "1.0.0", "danyx23/elm-mimetype": "4.0.1", @@ -40,7 +44,6 @@ "elm/file": "1.0.5", "elm/html": "1.0.1", "elm/http": "2.0.0", - "elm/parser": "1.1.0", "elm/random": "1.0.0", "elm/time": "1.0.0", "elm/virtual-dom": "1.0.5", @@ -54,7 +57,6 @@ "miniBill/elm-codec": "2.3.1", "miniBill/elm-unicode": "1.1.2", "noahzgordon/elm-color-extra": "1.0.2", - "pithub/elm-parser-bug-workaround": "1.0.0", "pithub/elm-parser-extra": "1.0.0", "robinheghan/fnv1a": "1.0.0", "rtfeldman/elm-css": "18.0.0", diff --git a/cli/src/Cli.elm b/cli/src/Cli.elm index 8dbb807..2fbc95e 100644 --- a/cli/src/Cli.elm +++ b/cli/src/Cli.elm @@ -27,6 +27,8 @@ import OpenApi.Config import OpenApi.Generate import Pages.Script import Pages.Script.Spinner +import Parser +import Parser.Error import Pretty import Regex exposing (Regex) import Result.Extra @@ -553,7 +555,7 @@ parseOriginal input original = case decodeMaybeYaml (OpenApi.Config.oasPath input) original of Err e -> e - |> parseErrorToFatalError + |> parseErrorToFatalError original |> BackendTask.fail Ok decoded -> @@ -573,8 +575,11 @@ mergeOverrides ( overrides, original ) = ) (overrides |> List.reverse - |> Result.Extra.combineMap (\( path, file ) -> decodeMaybeYaml path file) - |> Result.mapError parseErrorToFatalError + |> Result.Extra.combineMap + (\( path, file ) -> + decodeMaybeYaml path file + |> Result.mapError (parseErrorToFatalError file) + ) ) |> Result.Extra.join |> BackendTask.fromResult @@ -750,18 +755,36 @@ convertToSwaggerAndThenDecode config input value = |> BackendTask.andThen (\converted -> decodeOpenApiSpecOrFail { hasAttemptedToConvertFromSwagger = True } config input converted) -parseErrorToFatalError : ParseError -> FatalError.FatalError -parseErrorToFatalError parseError = +parseErrorToFatalError : String -> ParseError -> FatalError.FatalError +parseErrorToFatalError source parseError = case parseError of JsonDecodeError decodeError -> jsonErrorToFatalError decodeError - YamlParseError yamlError -> - yamlError - |> Yaml.Decode.errorToString + YamlParseError (Yaml.Decode.Decoding msg) -> + msg |> Ansi.Color.fontColor Ansi.Color.brightRed |> FatalError.fromString + YamlParseError (Yaml.Decode.Parsing deadEnds) -> + parserErrorToString source deadEnds + |> FatalError.fromString + + +parserErrorToString : String -> List Parser.DeadEnd -> String +parserErrorToString src deadEnds = + Parser.Error.renderError + { text = identity + , formatContext = Ansi.Color.fontColor Ansi.Color.cyan + , formatCaret = Ansi.Color.fontColor Ansi.Color.red + , newline = "\n" + , linesOfExtraContext = 3 + } + Parser.Error.forParser + src + deadEnds + |> String.concat + jsonErrorToFatalError : Json.Decode.Error -> FatalError.FatalError jsonErrorToFatalError decodeError = diff --git a/elm.json b/elm.json index 39282f2..fa4c540 100644 --- a/elm.json +++ b/elm.json @@ -27,7 +27,7 @@ "elm-explorations/test": "2.2.1 <= v < 3.0.0", "miniBill/elm-diff": "1.1.1 <= v < 2.0.0", "miniBill/elm-unicode": "1.1.1 <= v < 2.0.0", - "wolfadex/elm-ansi": "3.0.1 <= v < 4.0.0", - "MaybeJustJames/yaml": "2.1.7 <= v < 3.0.0" + "miniBill/elm-yaml": "1.0.0 <= v < 2.0.0", + "wolfadex/elm-ansi": "3.0.1 <= v < 4.0.0" } }