Rename Exception.Catchable -> Exception.Exception to reduce number of terms.

This commit is contained in:
Dillon Kearns 2023-01-10 11:06:20 -08:00
parent d68f943967
commit e5bcdf2d6e
14 changed files with 62 additions and 62 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ module Route.Showcase exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Css
import Exception exposing (Catchable, Throwable)
import Exception exposing (Exception, Throwable)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)

View File

@ -5,7 +5,7 @@ import BackendTask.File as File
import BackendTask.Glob as Glob
import Cloudinary
import Date exposing (Date)
import Exception exposing (Catchable, Throwable)
import Exception exposing (Exception, Throwable)
import Json.Decode as Decode exposing (Decoder)
import Pages.Url exposing (Url)
import Route
@ -27,7 +27,7 @@ blogPostsGlob =
|> Glob.toBackendTask
allMetadata : BackendTask.BackendTask (Catchable (File.FileReadError Decode.Error)) (List ( Route.Route, ArticleMetadata ))
allMetadata : BackendTask.BackendTask (Exception (File.FileReadError Decode.Error)) (List ( Route.Route, ArticleMetadata ))
allMetadata =
blogPostsGlob
|> BackendTask.map

View File

@ -2,7 +2,7 @@ module Test.HttpRequests exposing (all)
import BackendTask exposing (BackendTask)
import BackendTask.Http
import Exception exposing (Catchable)
import Exception exposing (Exception)
import Expect
import Json.Decode as Decode
import Test exposing (Test)
@ -112,7 +112,7 @@ all =
|> BackendTask.map (Test.describe "BackendTask tests")
test : String -> (Result error data -> Expect.Expectation) -> BackendTask (Catchable error) data -> BackendTask noError Test
test : String -> (Result error data -> Expect.Expectation) -> BackendTask (Exception error) data -> BackendTask noError Test
test name assert task =
task
|> BackendTask.toResult

View File

@ -76,7 +76,7 @@ data { pokedexNumber } =
|> BackendTask.map Response.render
get : String -> Decode.Decoder value -> BackendTask (Exception.Catchable BackendTask.Http.Error) value
get : String -> Decode.Decoder value -> BackendTask (Exception.Exception BackendTask.Http.Error) value
get url decoder =
BackendTask.Http.getWithOptions
{ url = url

View File

@ -86,7 +86,7 @@ Any place in your `elm-pages` app where the framework lets you pass in a value o
-}
import Exception exposing (Catchable(..), Throwable)
import Exception exposing (Exception(..), Throwable)
import Json.Encode
import Pages.StaticHttpRequest exposing (RawRequest(..))
@ -524,26 +524,26 @@ map9 combineFn request1 request2 request3 request4 request5 request6 request7 re
{-| -}
catch : BackendTask (Catchable error) value -> BackendTask error value
catch : BackendTask (Exception error) value -> BackendTask error value
catch ds =
ds
|> onError
(\exception ->
case exception of
Catchable error _ ->
Exception error _ ->
fail error
)
{-| -}
throw : BackendTask (Catchable error) data -> BackendTask Throwable data
throw : BackendTask (Exception error) data -> BackendTask Throwable data
throw backendTask =
backendTask
|> onError (Exception.throw >> fail)
{-| -}
toResult : BackendTask (Catchable error) data -> BackendTask noError (Result error data)
toResult : BackendTask (Exception error) data -> BackendTask noError (Result error data)
toResult backendTask =
backendTask
|> catch

View File

@ -39,7 +39,7 @@ down into the final `Data` value, it won't end up in the client!
import BackendTask exposing (BackendTask)
import BackendTask.Http
import BackendTask.Internal.Request
import Exception exposing (Catchable)
import Exception exposing (Exception)
import Json.Decode as Decode
import Json.Encode as Encode
import TerminalText
@ -65,7 +65,7 @@ get envVariableName =
{-| Get an environment variable, or a BackendTask failure if there is no environment variable matching that name.
-}
expect : String -> BackendTask (Catchable Error) String
expect : String -> BackendTask (Exception Error) String
expect envVariableName =
envVariableName
|> get
@ -73,7 +73,7 @@ expect envVariableName =
(\maybeValue ->
maybeValue
|> Result.fromMaybe
(Exception.Catchable (MissingEnvVariable envVariableName)
(Exception.Exception (MissingEnvVariable envVariableName)
{ title = "Missing Env Variable"
, body =
[ TerminalText.text "BackendTask.Env.expect was expecting a variable `"

View File

@ -51,7 +51,7 @@ plain old JSON in Elm.
import BackendTask exposing (BackendTask)
import BackendTask.Http
import BackendTask.Internal.Request
import Exception exposing (Catchable)
import Exception exposing (Exception)
import Json.Decode as Decode exposing (Decoder)
import TerminalText
@ -141,7 +141,7 @@ It's common to parse the body with a markdown parser or other format.
)
-}
bodyWithFrontmatter : (String -> Decoder frontmatter) -> String -> BackendTask (Catchable (FileReadError Decode.Error)) frontmatter
bodyWithFrontmatter : (String -> Decoder frontmatter) -> String -> BackendTask (Exception (FileReadError Decode.Error)) frontmatter
bodyWithFrontmatter frontmatterDecoder filePath =
read filePath
(body
@ -213,7 +213,7 @@ the [`BackendTask`](BackendTask) API along with [`BackendTask.Glob`](BackendTask
|> BackendTask.resolve
-}
onlyFrontmatter : Decoder frontmatter -> String -> BackendTask (Catchable (FileReadError Decode.Error)) frontmatter
onlyFrontmatter : Decoder frontmatter -> String -> BackendTask (Exception (FileReadError Decode.Error)) frontmatter
onlyFrontmatter frontmatterDecoder filePath =
read filePath
(frontmatter frontmatterDecoder)
@ -240,7 +240,7 @@ Hey there! This is my first post :)
Then data will yield the value `"Hey there! This is my first post :)"`.
-}
bodyWithoutFrontmatter : String -> BackendTask (Catchable (FileReadError decoderError)) String
bodyWithoutFrontmatter : String -> BackendTask (Exception (FileReadError decoderError)) String
bodyWithoutFrontmatter filePath =
read filePath
body
@ -264,7 +264,7 @@ You could read a file called `hello.txt` in your root project directory like thi
File.rawFile "hello.txt"
-}
rawFile : String -> BackendTask (Catchable (FileReadError decoderError)) String
rawFile : String -> BackendTask (Exception (FileReadError decoderError)) String
rawFile filePath =
read filePath (Decode.field "rawFile" Decode.string)
@ -286,7 +286,7 @@ The Decode will strip off any unused JSON data.
"elm.json"
-}
jsonFile : Decoder a -> String -> BackendTask (Catchable (FileReadError Decode.Error)) a
jsonFile : Decoder a -> String -> BackendTask (Exception (FileReadError Decode.Error)) a
jsonFile jsonFileDecoder filePath =
rawFile filePath
|> BackendTask.andThen
@ -295,7 +295,7 @@ jsonFile jsonFileDecoder filePath =
|> Decode.decodeString jsonFileDecoder
|> Result.mapError
(\jsonDecodeError ->
Exception.Catchable (DecodingError jsonDecodeError)
Exception.Exception (DecodingError jsonDecodeError)
{ title = "JSON Decoding Error"
, body =
[ TerminalText.text (Decode.errorToString jsonDecodeError)
@ -314,7 +314,7 @@ body =
Decode.field "withoutFrontmatter" Decode.string
read : String -> Decoder a -> BackendTask (Catchable (FileReadError error)) a
read : String -> Decoder a -> BackendTask (Exception (FileReadError error)) a
read filePath decoder =
BackendTask.Internal.Request.request
{ name = "read-file"
@ -330,10 +330,10 @@ read filePath decoder =
|> BackendTask.andThen BackendTask.fromResult
errorDecoder : String -> Decoder (Catchable (FileReadError decoding))
errorDecoder : String -> Decoder (Exception (FileReadError decoding))
errorDecoder filePath =
Decode.succeed
(Exception.Catchable FileDoesntExist
(Exception.Exception FileDoesntExist
{ title = "File Doesn't Exist"
, body =
[ TerminalText.text "Couldn't find file at path `"

View File

@ -229,7 +229,7 @@ import BackendTask exposing (BackendTask)
import BackendTask.Http
import BackendTask.Internal.Glob exposing (Glob(..))
import BackendTask.Internal.Request
import Exception exposing (Catchable, Throwable)
import Exception exposing (Exception, Throwable)
import Json.Decode as Decode
import Json.Encode as Encode
import List.Extra
@ -1054,7 +1054,7 @@ so it's ideal to make this kind of assertion rather than having fallback behavio
issues (like if we had instead ignored the case where there are two or more matching blog post files).
-}
expectUniqueMatch : Glob a -> BackendTask (Catchable String) a
expectUniqueMatch : Glob a -> BackendTask (Exception String) a
expectUniqueMatch glob =
glob
|> toBackendTask

View File

@ -104,7 +104,7 @@ import Base64
import Bytes exposing (Bytes)
import Bytes.Decode
import Dict exposing (Dict)
import Exception exposing (Catchable)
import Exception exposing (Exception)
import Json.Decode
import Json.Encode as Encode
import Pages.Internal.StaticHttpBody as Body
@ -157,10 +157,10 @@ type alias Body =
import BackendTask
import BackendTask.Http
import Exception exposing (Catchable)
import Exception exposing (Exception)
import Json.Decode as Decode exposing (Decoder)
getRequest : BackendTask (Catchable Error) Int
getRequest : BackendTask (Exception Error) Int
getRequest =
BackendTask.Http.getJson
"https://api.github.com/repos/dillonkearns/elm-pages"
@ -170,7 +170,7 @@ type alias Body =
getJson :
String
-> Json.Decode.Decoder a
-> BackendTask (Catchable Error) a
-> BackendTask (Exception Error) a
getJson url decoder =
getWithOptions
{ url = url
@ -189,9 +189,9 @@ use the more flexible `getWithOptions`.
import BackendTask
import BackendTask.Http
import Exception exposing (Catchable)
import Exception exposing (Exception)
getRequest : BackendTask (Catchable Error) String
getRequest : BackendTask (Exception Error) String
getRequest =
BackendTask.Http.get
"https://api.github.com/repos/dillonkearns/elm-pages"
@ -201,7 +201,7 @@ use the more flexible `getWithOptions`.
get :
String
-> Expect a
-> BackendTask (Catchable Error) a
-> BackendTask (Exception Error) a
get url expect =
getWithOptions
{ url = url
@ -231,7 +231,7 @@ getWithOptions :
, timeoutInMs : Maybe Int
, cachePath : Maybe String
}
-> BackendTask (Catchable Error) a
-> BackendTask (Exception Error) a
getWithOptions request__ =
let
request_ : HashRequest.Request
@ -258,7 +258,7 @@ post :
String
-> Body
-> Expect a
-> BackendTask (Catchable Error) a
-> BackendTask (Exception Error) a
post url body expect =
request
{ url = url
@ -397,7 +397,7 @@ request :
, timeoutInMs : Maybe Int
}
-> Expect a
-> BackendTask (Catchable Error) a
-> BackendTask (Exception Error) a
request request__ expect =
let
request_ : HashRequest.Request
@ -475,7 +475,7 @@ with this as a low-level detail, or you can use functions like [BackendTask.Http
requestRaw :
HashRequest.Request
-> Expect a
-> BackendTask (Catchable Error) a
-> BackendTask (Exception Error) a
requestRaw request__ expect =
let
request_ : HashRequest.Request
@ -573,7 +573,7 @@ requestRaw request__ expect =
|> BackendTask.fromResult
|> BackendTask.mapError
(\error ->
Exception.Catchable error (errorToString error)
Exception.Exception error (errorToString error)
)
)

View File

@ -14,7 +14,7 @@ module BackendTask.Port exposing
import BackendTask
import BackendTask.Http
import BackendTask.Internal.Request
import Exception exposing (Catchable)
import Exception exposing (Exception)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import TerminalText
@ -81,7 +81,7 @@ prefer to add ANSI color codes within the error string in an exception and it wi
As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using `fs.readFileSync`, because blocking IO can slow down your elm-pages builds and dev server.
-}
get : String -> Encode.Value -> Decoder b -> BackendTask.BackendTask (Catchable Error) b
get : String -> Encode.Value -> Decoder b -> BackendTask.BackendTask (Exception Error) b
get portName input decoder =
BackendTask.Internal.Request.request
{ name = "port"
@ -97,7 +97,7 @@ get portName input decoder =
|> Decode.andThen
(\errorKind ->
if errorKind == "PortNotDefined" then
Exception.Catchable (PortNotDefined { name = portName })
Exception.Exception (PortNotDefined { name = portName })
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I expected to find a port named `"
@ -114,7 +114,7 @@ get portName input decoder =
|> Decode.map (Maybe.withDefault "")
|> Decode.map
(\incorrectPortType ->
Exception.Catchable ExportIsNotFunction
Exception.Exception ExportIsNotFunction
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I found an export called `"
@ -127,7 +127,7 @@ get portName input decoder =
)
else if errorKind == "MissingPortsFile" then
Exception.Catchable MissingPortsFile
Exception.Exception MissingPortsFile
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I couldn't find your port-data-source file. Be sure to create a 'port-data-source.ts' or 'port-data-source.js' file."
@ -142,7 +142,7 @@ get portName input decoder =
|> Decode.map (Maybe.withDefault "")
|> Decode.map
(\errorMessage ->
Exception.Catchable
Exception.Exception
ErrorInPortsFile
{ title = "Port Error"
, body =
@ -160,7 +160,7 @@ get portName input decoder =
|> Decode.map (Maybe.withDefault Encode.null)
|> Decode.map
(\portCallError ->
Exception.Catchable
Exception.Exception
(PortCallError portCallError)
{ title = "Port Error"
, body =
@ -173,7 +173,7 @@ get portName input decoder =
)
else
Exception.Catchable ErrorInPortsFile
Exception.Exception ErrorInPortsFile
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I expected to find a port named `"

View File

@ -1,37 +1,37 @@
module Exception exposing (Throwable, Catchable(..), fromString, fromStringWithValue, throw)
module Exception exposing (Throwable, Exception(..), fromString, fromStringWithValue, throw)
{-|
@docs Throwable, Catchable, fromString, fromStringWithValue, throw
@docs Throwable, Exception, fromString, fromStringWithValue, throw
-}
{-| -}
type alias Throwable =
Catchable ()
Exception ()
{-| -}
type Catchable error
= Catchable error { title : String, body : String }
type Exception error
= Exception error { title : String, body : String }
{-| -}
fromString : String -> Catchable ()
fromString : String -> Exception ()
fromString string =
fromStringWithValue string ()
{-| -}
fromStringWithValue : String -> value -> Catchable value
fromStringWithValue : String -> value -> Exception value
fromStringWithValue string value =
Catchable value { title = "Custom Error", body = string }
Exception value { title = "Custom Error", body = string }
{-| -}
throw : Catchable error -> Catchable ()
throw : Exception error -> Exception ()
throw exception =
case exception of
Catchable _ string ->
Catchable () string
Exception _ string ->
Exception () string

View File

@ -2,7 +2,7 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), batchUpda
import BackendTask exposing (BackendTask)
import BuildError exposing (BuildError)
import Exception exposing (Catchable(..), Throwable)
import Exception exposing (Exception(..), Throwable)
import Json.Decode as Decode
import List.Extra
import Pages.StaticHttp.Request as HashRequest
@ -125,7 +125,7 @@ nextStep ({ allRawResponses, errors } as model) =
Just (Ok completed) ->
Finish completed
Just (Err (Catchable () buildError)) ->
Just (Err (Exception () buildError)) ->
FinishedWithErrors
[ { title = buildError.title |> String.toUpper
, path = "" -- TODO include path here

View File

@ -34,7 +34,7 @@ import BackendTask.Http
import BackendTask.Internal.Request
import Cli.OptionsParser as OptionsParser
import Cli.Program as Program
import Exception exposing (Catchable, Throwable)
import Exception exposing (Exception, Throwable)
import Json.Decode as Decode
import Json.Encode as Encode
import Pages.Internal.Script
@ -52,7 +52,7 @@ type Error
{-| -}
writeFile : { path : String, body : String } -> BackendTask (Catchable Error) ()
writeFile : { path : String, body : String } -> BackendTask (Exception Error) ()
writeFile { path, body } =
BackendTask.Internal.Request.request
{ name = "write-file"