Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cli/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
"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",
"json-tools/json-schema": "1.0.2",
"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",
Expand All @@ -28,6 +31,7 @@
"indirect": {
"BrianHicks/elm-string-graphemes": "1.0.4",
"Chadtech/elm-bool-extra": "2.4.2",
"MaybeJustJames/yaml": "2.1.7",
Comment thread
miniBill marked this conversation as resolved.
"NoRedInk/elm-json-decode-pipeline": "1.0.1",
"avh4/elm-color": "1.0.0",
"danyx23/elm-mimetype": "4.0.1",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
39 changes: 31 additions & 8 deletions cli/src/Cli.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Loading