Skip to content

Commit 3f40d11

Browse files
committed
Switch to miniBill/elm-yaml
1 parent 955692b commit 3f40d11

3 files changed

Lines changed: 38 additions & 13 deletions

File tree

cli/elm.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
"elm-version": "0.19.1",
88
"dependencies": {
99
"direct": {
10-
"MaybeJustJames/yaml": "2.1.7",
1110
"dillonkearns/elm-cli-options-parser": "5.0.1",
1211
"dillonkearns/elm-pages": "12.2.1",
1312
"elm/bytes": "1.0.8",
1413
"elm/core": "1.0.5",
1514
"elm/json": "1.1.4",
15+
"elm/parser": "1.1.0",
1616
"elm/regex": "1.0.0",
1717
"elm/url": "1.0.0",
1818
"elmcraft/core-extra": "2.3.0",
1919
"json-tools/json-schema": "1.0.2",
2020
"json-tools/json-value": "1.0.1",
2121
"mdgriffith/elm-codegen": "6.0.3",
2222
"miniBill/elm-fast-dict": "1.2.6",
23+
"miniBill/elm-parser-error-extra": "1.0.1",
24+
"miniBill/elm-yaml": "1.0.0",
25+
"pithub/elm-parser-bug-workaround": "1.0.0",
2326
"robinheghan/murmur3": "1.0.0",
2427
"the-sett/elm-pretty-printer": "3.3.1",
2528
"wolfadex/elm-ansi": "3.0.1",
@@ -28,6 +31,7 @@
2831
"indirect": {
2932
"BrianHicks/elm-string-graphemes": "1.0.4",
3033
"Chadtech/elm-bool-extra": "2.4.2",
34+
"MaybeJustJames/yaml": "2.1.7",
3135
"NoRedInk/elm-json-decode-pipeline": "1.0.1",
3236
"avh4/elm-color": "1.0.0",
3337
"danyx23/elm-mimetype": "4.0.1",
@@ -40,7 +44,6 @@
4044
"elm/file": "1.0.5",
4145
"elm/html": "1.0.1",
4246
"elm/http": "2.0.0",
43-
"elm/parser": "1.1.0",
4447
"elm/random": "1.0.0",
4548
"elm/time": "1.0.0",
4649
"elm/virtual-dom": "1.0.5",
@@ -54,7 +57,6 @@
5457
"miniBill/elm-codec": "2.3.1",
5558
"miniBill/elm-unicode": "1.1.2",
5659
"noahzgordon/elm-color-extra": "1.0.2",
57-
"pithub/elm-parser-bug-workaround": "1.0.0",
5860
"pithub/elm-parser-extra": "1.0.0",
5961
"robinheghan/fnv1a": "1.0.0",
6062
"rtfeldman/elm-css": "18.0.0",

cli/src/Cli.elm

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import OpenApi.Config
2727
import OpenApi.Generate
2828
import Pages.Script
2929
import Pages.Script.Spinner
30+
import Parser
31+
import Parser.Error
3032
import Pretty
3133
import Regex exposing (Regex)
3234
import Result.Extra
@@ -553,7 +555,7 @@ parseOriginal input original =
553555
case decodeMaybeYaml (OpenApi.Config.oasPath input) original of
554556
Err e ->
555557
e
556-
|> parseErrorToFatalError
558+
|> parseErrorToFatalError original
557559
|> BackendTask.fail
558560

559561
Ok decoded ->
@@ -573,8 +575,11 @@ mergeOverrides ( overrides, original ) =
573575
)
574576
(overrides
575577
|> List.reverse
576-
|> Result.Extra.combineMap (\( path, file ) -> decodeMaybeYaml path file)
577-
|> Result.mapError parseErrorToFatalError
578+
|> Result.Extra.combineMap
579+
(\( path, file ) ->
580+
decodeMaybeYaml path file
581+
|> Result.mapError (parseErrorToFatalError file)
582+
)
578583
)
579584
|> Result.Extra.join
580585
|> BackendTask.fromResult
@@ -750,18 +755,36 @@ convertToSwaggerAndThenDecode config input value =
750755
|> BackendTask.andThen (\converted -> decodeOpenApiSpecOrFail { hasAttemptedToConvertFromSwagger = True } config input converted)
751756

752757

753-
parseErrorToFatalError : ParseError -> FatalError.FatalError
754-
parseErrorToFatalError parseError =
758+
parseErrorToFatalError : String -> ParseError -> FatalError.FatalError
759+
parseErrorToFatalError source parseError =
755760
case parseError of
756761
JsonDecodeError decodeError ->
757762
jsonErrorToFatalError decodeError
758763

759-
YamlParseError yamlError ->
760-
yamlError
761-
|> Yaml.Decode.errorToString
764+
YamlParseError (Yaml.Decode.Decoding msg) ->
765+
msg
762766
|> Ansi.Color.fontColor Ansi.Color.brightRed
763767
|> FatalError.fromString
764768

769+
YamlParseError (Yaml.Decode.Parsing deadEnds) ->
770+
parserErrorToString source deadEnds
771+
|> FatalError.fromString
772+
773+
774+
parserErrorToString : String -> List Parser.DeadEnd -> String
775+
parserErrorToString src deadEnds =
776+
Parser.Error.renderError
777+
{ text = identity
778+
, formatContext = Ansi.Color.fontColor Ansi.Color.cyan
779+
, formatCaret = Ansi.Color.fontColor Ansi.Color.red
780+
, newline = "\n"
781+
, linesOfExtraContext = 3
782+
}
783+
Parser.Error.forParser
784+
src
785+
deadEnds
786+
|> String.concat
787+
765788

766789
jsonErrorToFatalError : Json.Decode.Error -> FatalError.FatalError
767790
jsonErrorToFatalError decodeError =

elm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"elm-explorations/test": "2.2.1 <= v < 3.0.0",
2828
"miniBill/elm-diff": "1.1.1 <= v < 2.0.0",
2929
"miniBill/elm-unicode": "1.1.1 <= v < 2.0.0",
30-
"wolfadex/elm-ansi": "3.0.1 <= v < 4.0.0",
31-
"MaybeJustJames/yaml": "2.1.7 <= v < 3.0.0"
30+
"miniBill/elm-yaml": "1.0.0 <= v < 2.0.0",
31+
"wolfadex/elm-ansi": "3.0.1 <= v < 4.0.0"
3232
}
3333
}

0 commit comments

Comments
 (0)