From 5ac445143369073a780c11add348657a32e52bfd Mon Sep 17 00:00:00 2001 From: Decio Ferreira Date: Wed, 11 Dec 2024 19:30:21 +0000 Subject: [PATCH] fix elm-review warnings --- review/src/ReviewConfig.elm | 5 +- src/Builder/Elm/Outline.elm | 37 --------- src/Compiler/AST/Utils/Binop.elm | 49 ----------- src/Compiler/Json/Decode.elm | 73 ----------------- src/Compiler/Json/Encode.elm | 113 -------------------------- src/Compiler/Reporting/Doc.elm | 16 +--- src/Data/Map.elm | 2 +- src/Serialize.elm | 16 +++- src/System/IO.elm | 42 +++++++++- src/Utils/Main.elm | 135 ------------------------------- 10 files changed, 58 insertions(+), 430 deletions(-) diff --git a/review/src/ReviewConfig.elm b/review/src/ReviewConfig.elm index 344bcadd3..12848e065 100644 --- a/review/src/ReviewConfig.elm +++ b/review/src/ReviewConfig.elm @@ -38,9 +38,8 @@ config = [ Docs.ReviewAtDocs.rule , NoConfusingPrefixOperator.rule , NoDebug.Log.rule - - -- , NoDebug.TodoOrToString.rule - -- |> Rule.ignoreErrorsForDirectories [ "tests/" ] + , NoDebug.TodoOrToString.rule + |> Rule.ignoreErrorsForDirectories [ "tests/" ] , NoExposingEverything.rule , NoImportingEverything.rule [] , NoMissingTypeAnnotation.rule diff --git a/src/Builder/Elm/Outline.elm b/src/Builder/Elm/Outline.elm index bddf98007..901595c84 100644 --- a/src/Builder/Elm/Outline.elm +++ b/src/Builder/Elm/Outline.elm @@ -10,8 +10,6 @@ module Builder.Elm.Outline exposing , flattenExposed , read , srcDirCodec - , srcDirDecoder - , srcDirEncoder , write ) @@ -29,8 +27,6 @@ import Compiler.Json.Decode as D import Compiler.Json.Encode as E import Compiler.Parse.Primitives as P import Data.Map as Dict exposing (Dict) -import Json.Decode as Decode -import Json.Encode as Encode import Serialize exposing (Codec) import System.IO as IO exposing (IO) import Utils.Main as Utils exposing (FilePath) @@ -423,39 +419,6 @@ boundParser bound tooLong = Err (P.PErr P.Consumed row newCol (\_ _ -> tooLong)) -srcDirEncoder : SrcDir -> Encode.Value -srcDirEncoder srcDir = - case srcDir of - AbsoluteSrcDir dir -> - Encode.object - [ ( "type", Encode.string "AbsoluteSrcDir" ) - , ( "dir", Encode.string dir ) - ] - - RelativeSrcDir dir -> - Encode.object - [ ( "type", Encode.string "RelativeSrcDir" ) - , ( "dir", Encode.string dir ) - ] - - -srcDirDecoder : Decode.Decoder SrcDir -srcDirDecoder = - Decode.field "type" Decode.string - |> Decode.andThen - (\type_ -> - case type_ of - "AbsoluteSrcDir" -> - Decode.map AbsoluteSrcDir (Decode.field "dir" Decode.string) - - "RelativeSrcDir" -> - Decode.map RelativeSrcDir (Decode.field "dir" Decode.string) - - _ -> - Decode.fail ("Failed to decode SrcDir's type: " ++ type_) - ) - - srcDirCodec : Codec e SrcDir srcDirCodec = Serialize.customType diff --git a/src/Compiler/AST/Utils/Binop.elm b/src/Compiler/AST/Utils/Binop.elm index 3c084c2f0..bea5ee8ab 100644 --- a/src/Compiler/AST/Utils/Binop.elm +++ b/src/Compiler/AST/Utils/Binop.elm @@ -2,15 +2,9 @@ module Compiler.AST.Utils.Binop exposing ( Associativity(..) , Precedence , associativityCodec - , associativityDecoder - , associativityEncoder , precedenceCodec - , precedenceDecoder - , precedenceEncoder ) -import Json.Decode as Decode -import Json.Encode as Encode import Serialize exposing (Codec) @@ -28,54 +22,11 @@ type Associativity | Right -precedenceEncoder : Precedence -> Encode.Value -precedenceEncoder = - Encode.int - - -precedenceDecoder : Decode.Decoder Precedence -precedenceDecoder = - Decode.int - - precedenceCodec : Codec e Precedence precedenceCodec = Serialize.int -associativityEncoder : Associativity -> Encode.Value -associativityEncoder associativity = - case associativity of - Left -> - Encode.string "Left" - - Non -> - Encode.string "Non" - - Right -> - Encode.string "Right" - - -associativityDecoder : Decode.Decoder Associativity -associativityDecoder = - Decode.string - |> Decode.andThen - (\str -> - case str of - "Left" -> - Decode.succeed Left - - "Non" -> - Decode.succeed Non - - "Right" -> - Decode.succeed Right - - _ -> - Decode.fail ("Unknown Associativity: " ++ str) - ) - - associativityCodec : Codec e Associativity associativityCodec = Serialize.customType diff --git a/src/Compiler/Json/Decode.elm b/src/Compiler/Json/Decode.elm index 431160056..60f7a6006 100644 --- a/src/Compiler/Json/Decode.elm +++ b/src/Compiler/Json/Decode.elm @@ -7,107 +7,34 @@ module Compiler.Json.Decode exposing , Problem(..) , StringProblem(..) , apply - , assocListDict , bind , customString , dict - , everySet , failure , field , fmap , fromByteString , int - , jsonPair , list , mapError , nonEmptyList - , nonempty , oneOf - , oneOrMore , pair , pairs , pure - , result , string ) import Compiler.Data.NonEmptyList as NE -import Compiler.Data.OneOrMore as OneOrMore exposing (OneOrMore) import Compiler.Json.String as Json import Compiler.Parse.Keyword as K import Compiler.Parse.Primitives as P exposing (Col, Row) import Compiler.Reporting.Annotation as A import Data.Map as Dict exposing (Dict) -import Data.Set as EverySet exposing (EverySet) -import Json.Decode as Decode import Utils.Crash exposing (crash) --- CORE HELPERS - - -assocListDict : (k -> comparable) -> Decode.Decoder k -> Decode.Decoder v -> Decode.Decoder (Dict comparable k v) -assocListDict toComparable keyDecoder valueDecoder = - Decode.list (jsonPair keyDecoder valueDecoder) - |> Decode.map (Dict.fromList toComparable) - - -jsonPair : Decode.Decoder a -> Decode.Decoder b -> Decode.Decoder ( a, b ) -jsonPair firstDecoder secondDecoder = - Decode.map2 Tuple.pair - (Decode.field "a" firstDecoder) - (Decode.field "b" secondDecoder) - - -everySet : (a -> comparable) -> Decode.Decoder a -> Decode.Decoder (EverySet comparable a) -everySet toComparable decoder = - Decode.list decoder - |> Decode.map (EverySet.fromList toComparable) - - -nonempty : Decode.Decoder a -> Decode.Decoder (NE.Nonempty a) -nonempty decoder = - Decode.list decoder - |> Decode.andThen - (\values -> - case values of - x :: xs -> - Decode.succeed (NE.Nonempty x xs) - - [] -> - Decode.fail "Empty list when it should have at least one element (non-empty list)!" - ) - - -oneOrMore : Decode.Decoder a -> Decode.Decoder (OneOrMore a) -oneOrMore decoder = - Decode.oneOf - [ Decode.map OneOrMore.one (Decode.field "one" decoder) - , Decode.map2 OneOrMore.more - (Decode.field "left" (Decode.lazy (\_ -> oneOrMore decoder))) - (Decode.field "right" (Decode.lazy (\_ -> oneOrMore decoder))) - ] - - -result : Decode.Decoder x -> Decode.Decoder a -> Decode.Decoder (Result x a) -result errDecoder successDecoder = - Decode.field "type" Decode.string - |> Decode.andThen - (\type_ -> - case type_ of - "Err" -> - Decode.map Err (Decode.field "value" errDecoder) - - "Ok" -> - Decode.map Ok (Decode.field "value" successDecoder) - - _ -> - Decode.fail ("Failed to decode result's type: " ++ type_) - ) - - - -- RUNNERS diff --git a/src/Compiler/Json/Encode.elm b/src/Compiler/Json/Encode.elm index 890df1c51..892aad592 100644 --- a/src/Compiler/Json/Encode.elm +++ b/src/Compiler/Json/Encode.elm @@ -1,104 +1,25 @@ module Compiler.Json.Encode exposing ( Value(..) , array - , assocListDict , bool , chars , dict , encodeUgly - , everySet , int - , jsonPair , list - , maybe , name - , nonempty , null - , number , object - , oneOrMore - , result , string - , toJsonValue , write , writeUgly ) -import Compiler.Data.NonEmptyList as NE -import Compiler.Data.OneOrMore exposing (OneOrMore(..)) import Data.Map as Dict exposing (Dict) -import Data.Set as EverySet exposing (EverySet) -import Json.Encode as Encode import System.IO as IO exposing (IO(..)) --- CORE HELPERS - - -assocListDict : (k -> k -> Order) -> (k -> Encode.Value) -> (v -> Encode.Value) -> Dict c k v -> Encode.Value -assocListDict keyComparison keyEncoder valueEncoder = - Encode.list (jsonPair keyEncoder valueEncoder) << List.reverse << Dict.toList keyComparison - - -jsonPair : (a -> Encode.Value) -> (b -> Encode.Value) -> ( a, b ) -> Encode.Value -jsonPair firstEncoder secondEncoder ( a, b ) = - Encode.object - [ ( "a", firstEncoder a ) - , ( "b", secondEncoder b ) - ] - - -everySet : (a -> a -> Order) -> (a -> Encode.Value) -> EverySet c a -> Encode.Value -everySet keyComparison encoder = - Encode.list encoder << List.reverse << EverySet.toList keyComparison - - -result : (x -> Encode.Value) -> (a -> Encode.Value) -> Result x a -> Encode.Value -result errEncoder successEncoder resultValue = - case resultValue of - Ok value -> - Encode.object - [ ( "type", Encode.string "Ok" ) - , ( "value", successEncoder value ) - ] - - Err err -> - Encode.object - [ ( "type", Encode.string "Err" ) - , ( "value", errEncoder err ) - ] - - -maybe : (a -> Encode.Value) -> Maybe a -> Encode.Value -maybe encoder maybeValue = - case maybeValue of - Just value -> - encoder value - - Nothing -> - Encode.null - - -nonempty : (a -> Encode.Value) -> NE.Nonempty a -> Encode.Value -nonempty encoder (NE.Nonempty x xs) = - Encode.list encoder (x :: xs) - - -oneOrMore : (a -> Encode.Value) -> OneOrMore a -> Encode.Value -oneOrMore encoder oneOrMore_ = - case oneOrMore_ of - One value -> - Encode.object [ ( "one", encoder value ) ] - - More left right -> - Encode.object - [ ( "left", oneOrMore encoder left ) - , ( "right", oneOrMore encoder right ) - ] - - - -- VALUES @@ -142,11 +63,6 @@ int = Integer -number : Float -> Value -number = - Number - - null : Value null = Null @@ -359,32 +275,3 @@ encodeObject indent first rest = encodeField : String -> ( String, Value ) -> String encodeField indent ( key, value ) = "\"" ++ key ++ "\": " ++ encodeHelp indent value - - - --- JSON VALUE - - -toJsonValue : Value -> Encode.Value -toJsonValue value = - case value of - Array arr -> - Encode.list toJsonValue arr - - Object obj -> - Encode.object (List.map (Tuple.mapSecond toJsonValue) obj) - - StringVal builder -> - Encode.string builder - - Boolean boolean -> - Encode.bool boolean - - Integer n -> - Encode.int n - - Number scientific -> - Encode.float scientific - - Null -> - Encode.null diff --git a/src/Compiler/Reporting/Doc.elm b/src/Compiler/Reporting/Doc.elm index 911fca56e..f8c5e8d34 100644 --- a/src/Compiler/Reporting/Doc.elm +++ b/src/Compiler/Reporting/Doc.elm @@ -12,7 +12,7 @@ module Compiler.Reporting.Doc exposing , stack, reflow, commaSep , toSimpleNote, toFancyNote, toSimpleHint, toFancyHint , link, fancyLink, reflowLink, makeLink, makeNakedLink - , args, moreArgs, ordinal, intToOrdinal, cycle + , args, ordinal, intToOrdinal, cycle ) {-| @@ -30,7 +30,7 @@ module Compiler.Reporting.Doc exposing @docs stack, reflow, commaSep @docs toSimpleNote, toFancyNote, toSimpleHint, toFancyHint @docs link, fancyLink, reflowLink, makeLink, makeNakedLink -@docs args, moreArgs, ordinal, intToOrdinal, cycle +@docs args, ordinal, intToOrdinal, cycle -} @@ -212,18 +212,6 @@ args n = ) -moreArgs : Int -> String -moreArgs n = - String.fromInt n - ++ " more" - ++ (if n == 1 then - " argument" - - else - " arguments" - ) - - ordinal : Index.ZeroBased -> String ordinal index = intToOrdinal (Index.toHuman index) diff --git a/src/Data/Map.elm b/src/Data/Map.elm index af2e0f30e..1c4a8a23a 100644 --- a/src/Data/Map.elm +++ b/src/Data/Map.elm @@ -277,7 +277,7 @@ merge : -> Dict comparable k b -> result -> result -merge keyComparison leftStep bothStep rightStep (D leftDict) (D rightDict) initialResult = +merge _ leftStep bothStep rightStep (D leftDict) (D rightDict) initialResult = Dict.merge (\_ ( k, a ) -> leftStep k a) (\_ ( k, a ) ( _, b ) -> bothStep k a b) diff --git a/src/Serialize.elm b/src/Serialize.elm index 4393fbda1..75f628959 100644 --- a/src/Serialize.elm +++ b/src/Serialize.elm @@ -4,10 +4,9 @@ module Serialize exposing , string, bool, float, int, unit, bytes, byte , maybe, list, array, dict, set, tuple, triple, result, enum , RecordCodec, record, field, finishRecord - , CustomTypeCodec, customType, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, finishCustomType, VariantEncoder + , CustomTypeCodec, customType, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, finishCustomType, VariantEncoder , map, mapValid, mapError , lazy - , variant9 ) {-| Ref.: **Initial implementation from `MartinSStewart/elm-serialize/1.3.1`** @@ -49,7 +48,7 @@ Here's some advice when choosing: # Custom Types -@docs CustomTypeCodec, customType, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, finishCustomType, VariantEncoder +@docs CustomTypeCodec, customType, variant0, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, finishCustomType, VariantEncoder # Mapping @@ -141,6 +140,7 @@ getJsonDecoderHelper (Codec m) = decodeFromBytes : Codec e a -> Bytes.Bytes -> Result (Error e) a decodeFromBytes codec bytes_ = let + decoder : BD.Decoder (Result (Error e) a) decoder = BD.unsignedInt8 |> BD.andThen @@ -208,6 +208,7 @@ decodeFromString codec base64 = decodeFromJson : Codec e a -> JE.Value -> Result (Error e) a decodeFromJson codec json = let + decoder : JD.Decoder (Result (Error e) a) decoder = JD.index 0 JD.int |> JD.andThen @@ -274,6 +275,7 @@ getJsonDecoder errorToString codec = decode : String -> Maybe Bytes.Bytes decode base64text = let + replaceChar : Regex.Match -> String replaceChar rematch = case rematch.match of "-" -> @@ -282,6 +284,7 @@ decode base64text = _ -> "/" + strlen : Int strlen = String.length base64text in @@ -290,9 +293,11 @@ decode base64text = else let + hanging : Int hanging = modBy 4 strlen + ilen : Int ilen = if hanging == 0 then 0 @@ -366,6 +371,7 @@ encodeToJson codec value = replaceBase64Chars : Bytes.Bytes -> String replaceBase64Chars = let + replaceChar : Regex.Match -> String replaceChar rematch = case rematch.match of "+" -> @@ -758,12 +764,14 @@ It's safe to add items to the end of the list though. enum : a -> List a -> Codec e a enum defaultItem items = let + getIndex : a -> Int getIndex value = items |> findIndex ((==) value) |> Maybe.withDefault -1 |> (+) 1 + getItem : Int -> Result (Error e) a getItem index = if index < 0 then Err DataCorrupted @@ -1944,4 +1952,4 @@ lazy f = (\value -> getBytesEncoderHelper (f ()) value) (BD.succeed () |> BD.andThen (\() -> getBytesDecoderHelper (f ()))) (\value -> getJsonEncoderHelper (f ()) value) - (JD.succeed () |> JD.andThen (\() -> getJsonDecoderHelper (f ()))) + (JD.lazy (\() -> getJsonDecoderHelper (f ()))) diff --git a/src/System/IO.elm b/src/System/IO.elm index acda3e0dc..1792bfc0c 100644 --- a/src/System/IO.elm +++ b/src/System/IO.elm @@ -137,6 +137,10 @@ run app = , recvDirCanonicalizePath (\{ index, value } -> DirCanonicalizePathMsg index value) , recvBinaryDecodeFileOrFail (\{ index, value } -> BinaryDecodeFileOrFailMsg index value) , recvWrite WriteMsg + , recvDirRemoveFile DirRemoveFileMsg + , recvDirRemoveDirectoryRecursive DirRemoveDirectoryRecursiveMsg + , recvDirWithCurrentDirectory DirWithCurrentDirectoryMsg + , recvReplGetInputLineWithInitial (\{ index, value } -> ReplGetInputLineWithInitialMsg index value) , recvNewEmptyMVar (\{ index, value } -> NewEmptyMVarMsg index value) , recvReadMVar (\{ index, value } -> ReadMVarMsg index value) , recvPutMVar PutMVarMsg @@ -212,6 +216,10 @@ type Msg | DirCanonicalizePathMsg Int FilePath | BinaryDecodeFileOrFailMsg Int Encode.Value | WriteMsg Int + | DirRemoveFileMsg Int + | DirRemoveDirectoryRecursiveMsg Int + | DirWithCurrentDirectoryMsg Int + | ReplGetInputLineWithInitialMsg Int (Maybe String) | NewEmptyMVarMsg Int Int | ReadMVarMsg Int Encode.Value | PutMVarMsg Int @@ -575,6 +583,38 @@ update msg model = _ -> crash "WriteMsg" + DirRemoveFileMsg index -> + case Dict.get index model.next of + Just (DirRemoveFileNext fn) -> + update (PureMsg index (fn ())) model + + _ -> + crash "DirRemoveFileMsg" + + DirRemoveDirectoryRecursiveMsg index -> + case Dict.get index model.next of + Just (DirRemoveDirectoryRecursiveNext fn) -> + update (PureMsg index (fn ())) model + + _ -> + crash "DirRemoveDirectoryRecursiveMsg" + + DirWithCurrentDirectoryMsg index -> + case Dict.get index model.next of + Just (DirWithCurrentDirectoryNext fn) -> + update (PureMsg index (fn ())) model + + _ -> + crash "DirWithCurrentDirectoryMsg" + + ReplGetInputLineWithInitialMsg index value -> + case Dict.get index model.next of + Just (ReplGetInputLineWithInitialNext fn) -> + update (PureMsg index (fn value)) model + + _ -> + crash "ReplGetInputLineWithInitialMsg" + port sendGetLine : Int -> Cmd msg @@ -744,7 +784,7 @@ port recvDirWithCurrentDirectory : (Int -> msg) -> Sub msg port sendReplGetInputLineWithInitial : { index : Int, prompt : String, left : String, right : String } -> Cmd msg -port recvReplGetInputLineWithInitial : (Maybe String -> msg) -> Sub msg +port recvReplGetInputLineWithInitial : ({ index : Int, value : Maybe String } -> msg) -> Sub msg diff --git a/src/Utils/Main.elm b/src/Utils/Main.elm index 0baebe3e2..72b101b77 100644 --- a/src/Utils/Main.elm +++ b/src/Utils/Main.elm @@ -57,8 +57,6 @@ module Utils.Main exposing , fpTakeExtension , fpTakeFileName , httpExceptionContentCodec - , httpExceptionContentDecoder - , httpExceptionContentEncoder , httpHLocation , httpResponseHeaders , httpResponseStatus @@ -75,8 +73,6 @@ module Utils.Main exposing , listTraverse_ , lockWithFileLock , mVarCodec - , mVarDecoder - , mVarEncoder , mapFindMin , mapFromKeys , mapFromListWith @@ -94,7 +90,6 @@ module Utils.Main exposing , mapUnionWith , mapUnions , mapUnionsWith - , maybeEncoder , maybeMapM , maybeTraverseTask , newChan @@ -116,8 +111,6 @@ module Utils.Main exposing , sequenceListMaybe , sequenceNonemptyListResult , someExceptionCodec - , someExceptionDecoder - , someExceptionEncoder , takeMVar , unlines , unzip3 @@ -129,16 +122,11 @@ import Basics.Extra exposing (flip) import Builder.Reporting.Task as Task exposing (Task) import Compiler.Data.Index as Index import Compiler.Data.NonEmptyList as NE -import Compiler.Elm.Version exposing (toComparable) -import Compiler.Json.Decode as D -import Compiler.Json.Encode as E import Compiler.Reporting.Result as R import Control.Monad.State.Strict as State import Data.Map as Map exposing (Dict) import Data.Set as EverySet exposing (EverySet) import Dict -import Json.Decode as Decode -import Json.Encode as Encode import Maybe.Extra as Maybe import Prelude import Serialize exposing (Codec) @@ -196,16 +184,6 @@ mapFromListWith toComparable f = Map.empty -maybeEncoder : (a -> Encode.Value) -> Maybe a -> Encode.Value -maybeEncoder encoder maybeValue = - case maybeValue of - Just value -> - encoder value - - Nothing -> - Encode.null - - eitherLefts : List (Result e a) -> List e eitherLefts = List.filterMap @@ -1130,16 +1108,6 @@ replGetInputLineWithInitial prompt ( left, right ) = -- ENCODERS and DECODERS -mVarEncoder : MVar a -> Encode.Value -mVarEncoder (MVar ref) = - Encode.int ref - - -mVarDecoder : Decode.Decoder (MVar a) -mVarDecoder = - Decode.map MVar Decode.int - - mVarCodec : Codec e (MVar a) mVarCodec = Serialize.int |> Serialize.map MVar (\(MVar ref) -> ref) @@ -1155,16 +1123,6 @@ chItemCodec codec = |> Serialize.finishCustomType -someExceptionEncoder : SomeException -> Encode.Value -someExceptionEncoder _ = - Encode.object [ ( "type", Encode.string "SomeException" ) ] - - -someExceptionDecoder : Decode.Decoder SomeException -someExceptionDecoder = - Decode.succeed SomeException - - someExceptionCodec : Codec e SomeException someExceptionCodec = Serialize.customType @@ -1175,99 +1133,6 @@ someExceptionCodec = |> Serialize.finishCustomType -httpResponseEncoder : HttpResponse body -> Encode.Value -httpResponseEncoder (HttpResponse httpResponse) = - Encode.object - [ ( "type", Encode.string "HttpResponse" ) - , ( "responseStatus", httpStatusEncoder httpResponse.responseStatus ) - , ( "responseHeaders", httpResponseHeadersEncoder httpResponse.responseHeaders ) - ] - - -httpResponseDecoder : Decode.Decoder (HttpResponse body) -httpResponseDecoder = - Decode.map2 - (\responseStatus responseHeaders -> - HttpResponse - { responseStatus = responseStatus - , responseHeaders = responseHeaders - } - ) - (Decode.field "responseStatus" httpStatusDecoder) - (Decode.field "responseHeaders" httpResponseHeadersDecoder) - - -httpStatusEncoder : HttpStatus -> Encode.Value -httpStatusEncoder (HttpStatus statusCode statusMessage) = - Encode.object - [ ( "type", Encode.string "HttpStatus" ) - , ( "statusCode", Encode.int statusCode ) - , ( "statusMessage", Encode.string statusMessage ) - ] - - -httpStatusDecoder : Decode.Decoder HttpStatus -httpStatusDecoder = - Decode.map2 HttpStatus - (Decode.field "statusCode" Decode.int) - (Decode.field "statusMessage" Decode.string) - - -httpResponseHeadersEncoder : HttpResponseHeaders -> Encode.Value -httpResponseHeadersEncoder = - Encode.list (E.jsonPair Encode.string Encode.string) - - -httpResponseHeadersDecoder : Decode.Decoder HttpResponseHeaders -httpResponseHeadersDecoder = - Decode.list (D.jsonPair Decode.string Decode.string) - - -httpExceptionContentEncoder : HttpExceptionContent -> Encode.Value -httpExceptionContentEncoder httpExceptionContent = - case httpExceptionContent of - StatusCodeException response body -> - Encode.object - [ ( "type", Encode.string "StatusCodeException" ) - , ( "response", httpResponseEncoder response ) - , ( "body", Encode.string body ) - ] - - TooManyRedirects responses -> - Encode.object - [ ( "type", Encode.string "TooManyRedirects" ) - , ( "responses", Encode.list httpResponseEncoder responses ) - ] - - ConnectionFailure someException -> - Encode.object - [ ( "type", Encode.string "ConnectionFailure" ) - , ( "someException", someExceptionEncoder someException ) - ] - - -httpExceptionContentDecoder : Decode.Decoder HttpExceptionContent -httpExceptionContentDecoder = - Decode.field "type" Decode.string - |> Decode.andThen - (\type_ -> - case type_ of - "StatusCodeException" -> - Decode.map2 StatusCodeException - (Decode.field "response" httpResponseDecoder) - (Decode.field "body" Decode.string) - - "TooManyRedirects" -> - Decode.map TooManyRedirects (Decode.field "responses" (Decode.list httpResponseDecoder)) - - "ConnectionFailure" -> - Decode.map ConnectionFailure (Decode.field "someException" someExceptionDecoder) - - _ -> - Decode.fail ("Failed to decode HttpExceptionContent's type: " ++ type_) - ) - - httpExceptionContentCodec : Codec e HttpExceptionContent httpExceptionContentCodec = Serialize.customType