@@ -27,6 +27,8 @@ import OpenApi.Config
2727import OpenApi.Generate
2828import Pages.Script
2929import Pages.Script.Spinner
30+ import Parser
31+ import Parser.Error
3032import Pretty
3133import Regex exposing (Regex )
3234import 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
766789jsonErrorToFatalError : Json .Decode .Error -> FatalError .FatalError
767790jsonErrorToFatalError decodeError =
0 commit comments