Rename Exception -> RecoverableError.

This commit is contained in:
Dillon Kearns 2023-01-16 15:22:44 -08:00
parent 0b54107831
commit 60afaee624
107 changed files with 490 additions and 446 deletions

View File

@ -665,7 +665,7 @@ otherFile routes phaseString =
}
|> Elm.withType
(Gen.BackendTask.annotation_.backendTask
(Type.named [ "Exception" ] "Throwable")
(Type.named [ "FatalError" ] "FatalError")
(Gen.Server.Response.annotation_.response
(Type.named [] "PageData")
(Type.named [ "ErrorPage" ] "ErrorPage")
@ -715,7 +715,7 @@ otherFile routes phaseString =
}
|> Elm.withType
(Gen.BackendTask.annotation_.backendTask
(Type.named [ "Exception" ] "Throwable")
(Type.named [ "FatalError" ] "FatalError")
(Gen.Server.Response.annotation_.response
(Type.named [] "ActionData")
(Type.named [ "ErrorPage" ] "ErrorPage")
@ -1429,7 +1429,7 @@ otherFile routes phaseString =
}
|> Elm.withType
(Gen.BackendTask.annotation_.backendTask
(Type.named [ "Exception" ] "Throwable")
(Type.named [ "FatalError" ] "FatalError")
(Type.maybe Gen.Pages.Internal.NotFoundReason.annotation_.notFoundReason)
)
)
@ -1869,7 +1869,7 @@ otherFile routes phaseString =
|> Gen.BackendTask.call_.map Gen.List.values_.concat
|> Elm.withType
(Gen.BackendTask.annotation_.backendTask
(Type.named [ "Exception" ] "Throwable")
(Type.named [ "FatalError" ] "FatalError")
(Type.list Gen.Head.annotation_.tag)
)
)
@ -1991,7 +1991,7 @@ otherFile routes phaseString =
|> Gen.BackendTask.call_.map Gen.List.values_.concat
|> Elm.withType
(Gen.BackendTask.annotation_.backendTask
(Type.named [ "Exception" ] "Throwable")
(Type.named [ "FatalError" ] "FatalError")
(Type.list (Type.named [ "Route" ] "Route"))
)
)

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,7 @@
"ApiRoute",
"Path",
"Pages.PageUrl",
"Exception",
"FatalError",
"QueryParams",
"Pages.Url",
"BackendTask",

View File

@ -2,13 +2,13 @@ module Api exposing (routes)
import ApiRoute
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Route exposing (Route)
routes :
BackendTask Throwable (List Route)
BackendTask FatalError (List Route)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =

View File

@ -1,7 +1,7 @@
module Route.Index exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (text)
@ -45,7 +45,7 @@ type alias Data =
()
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -3,7 +3,7 @@ module Route.SubPage exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Css exposing (..)
import Css.Global
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (..)
@ -46,7 +46,7 @@ type alias Data =
()
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -2,7 +2,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Html.Styled
import Pages.Flags
@ -76,7 +76,7 @@ subscriptions _ _ =
Sub.none
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -2,7 +2,7 @@ module Site exposing (config)
import BackendTask exposing (BackendTask)
import Cloudinary
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import MimeType
import Pages.Manifest as Manifest
@ -23,7 +23,7 @@ type alias Data =
}
head : BackendTask Throwable (List Head.Tag)
head : BackendTask FatalError (List Head.Tag)
head =
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")

View File

@ -4,7 +4,7 @@ import ApiRoute
import Article
import BackendTask exposing (BackendTask)
import BackendTask.Http
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html exposing (Html)
import Json.Decode as Decode
@ -21,7 +21,7 @@ import Time
routes :
BackendTask Throwable (List Route)
BackendTask FatalError (List Route)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =
@ -105,7 +105,7 @@ routes getStaticRoutes htmlToString =
]
postsBackendTask : BackendTask Throwable (List Rss.Item)
postsBackendTask : BackendTask FatalError (List Rss.Item)
postsBackendTask =
Article.allMetadata
|> BackendTask.map
@ -136,7 +136,7 @@ rss :
, builtAt : Time.Posix
, indexPage : List String
}
-> BackendTask Throwable (List Rss.Item)
-> BackendTask FatalError (List Rss.Item)
-> ApiRoute.ApiRoute ApiRoute.Response
rss options itemsRequest =
ApiRoute.succeed

View File

@ -4,7 +4,7 @@ import Article
import BackendTask exposing (BackendTask)
import BuildError exposing (BuildError)
import Date
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -35,7 +35,7 @@ route =
}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
Article.allMetadata
|> BackendTask.throw

View File

@ -7,7 +7,7 @@ import Cloudinary
import Data.Author as Author exposing (Author)
import Date exposing (Date)
import DateOrDateTime
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -53,7 +53,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
Article.blogPostsGlob
|> BackendTask.map
@ -241,7 +241,7 @@ type alias ActionData =
{}
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
MarkdownCodec.withFrontmatter Data
frontmatterDecoder

View File

@ -6,7 +6,7 @@ import BackendTask.Glob as Glob exposing (Glob)
import Css
import Css.Global
import DocsSection exposing (Section)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Heroicon
@ -55,7 +55,7 @@ route =
}
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
DocsSection.all
|> BackendTask.map
@ -70,7 +70,7 @@ pages =
)
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.map4 Data
(pageBody routeParams)
@ -90,7 +90,7 @@ filePathToEditUrl filePath =
"https://github.com/dillonkearns/elm-pages/edit/master/examples/docs/" ++ filePath
previousAndNextData : RouteParams -> BackendTask Throwable { title : String, previousAndNext : ( Maybe NextPrevious.Item, Maybe NextPrevious.Item ) }
previousAndNextData : RouteParams -> BackendTask FatalError { title : String, previousAndNext : ( Maybe NextPrevious.Item, Maybe NextPrevious.Item ) }
previousAndNextData current =
DocsSection.all
|> BackendTask.andThen
@ -105,7 +105,7 @@ previousAndNextData current =
BackendTask.map2 (\title previousAndNext -> { title = title, previousAndNext = previousAndNext })
(List.Extra.getAt index sections
|> maybeBackendTask titleForSection
|> BackendTask.map (Result.fromMaybe (Exception.fromString "Couldn't find section"))
|> BackendTask.map (Result.fromMaybe (FatalError.fromString "Couldn't find section"))
|> BackendTask.andThen BackendTask.fromResult
|> BackendTask.map .title
)
@ -130,7 +130,7 @@ maybeBackendTask fn maybe =
BackendTask.succeed Nothing
titleForSection : Section -> BackendTask Throwable NextPrevious.Item
titleForSection : Section -> BackendTask FatalError NextPrevious.Item
titleForSection section =
Glob.expectUniqueMatch (findBySlug section.slug)
|> BackendTask.throw
@ -159,7 +159,7 @@ titleForSection section =
|> BackendTask.andThen
(\maybeTitle ->
maybeTitle
|> Result.fromMaybe (Exception.fromString "Expected to find an H1 heading in this markdown.")
|> Result.fromMaybe (FatalError.fromString "Expected to find an H1 heading in this markdown.")
|> BackendTask.fromResult
)
@ -285,7 +285,7 @@ view maybeUrl sharedModel static =
}
filePathBackendTask : RouteParams -> BackendTask Throwable String
filePathBackendTask : RouteParams -> BackendTask FatalError String
filePathBackendTask routeParams =
let
slug : String
@ -297,7 +297,7 @@ filePathBackendTask routeParams =
|> BackendTask.throw
pageBody : RouteParams -> BackendTask Throwable (List Block)
pageBody : RouteParams -> BackendTask FatalError (List Block)
pageBody routeParams =
routeParams
|> filePathBackendTask
@ -316,9 +316,9 @@ findBySlug slug =
|> Glob.match (Glob.literal ".md")
markdownBody : String -> BackendTask Throwable (List Block)
markdownBody : String -> BackendTask FatalError (List Block)
markdownBody rawBody =
rawBody
|> Markdown.Parser.parse
|> Result.mapError (\_ -> Exception.fromString "Markdown parsing error")
|> Result.mapError (\_ -> FatalError.fromString "Markdown parsing error")
|> BackendTask.fromResult

View File

@ -2,7 +2,7 @@ module Route.Index exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Css
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (..)
@ -86,7 +86,7 @@ view maybeUrl sharedModel static =
}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -2,7 +2,7 @@ module Route.Showcase exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Css
import Exception exposing (Exception, Throwable)
import FatalError exposing (FatalError, Recoverable)
import Head
import Head.Seo as Seo
import Html.Styled exposing (..)
@ -40,7 +40,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
Showcase.staticRequest

View File

@ -3,7 +3,7 @@ module Shared exposing (Data, Model, Msg, template)
import BackendTask exposing (BackendTask)
import DocsSection
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Html.Styled
import Pages.Flags
@ -86,7 +86,7 @@ subscriptions _ _ =
Sub.none
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
TableOfContents.backendTask DocsSection.all

View File

@ -2,7 +2,7 @@ module Site exposing (canonicalUrl, config)
import BackendTask exposing (BackendTask)
import Cloudinary
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import MimeType
import Pages.Url
@ -16,7 +16,7 @@ config =
}
head : BackendTask Throwable (List Head.Tag)
head : BackendTask FatalError (List Head.Tag)
head =
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")

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 (Exception, Throwable)
import FatalError exposing (FatalError, Recoverable)
import Json.Decode as Decode exposing (Decoder)
import Pages.Url exposing (Url)
import Route
@ -27,7 +27,7 @@ blogPostsGlob =
|> Glob.toBackendTask
allMetadata : BackendTask.BackendTask (Exception (File.FileReadError Decode.Error)) (List ( Route.Route, ArticleMetadata ))
allMetadata : BackendTask.BackendTask (Recoverable (File.FileReadError Decode.Error)) (List ( Route.Route, ArticleMetadata ))
allMetadata =
blogPostsGlob
|> BackendTask.map

View File

@ -4,7 +4,7 @@ import BackendTask exposing (BackendTask)
import BackendTask.Env as Env
import BackendTask.Http
import BuildError exposing (BuildError)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Extra
@ -39,7 +39,7 @@ entryDecoder =
(Decode.maybe (Decode.field "Repository URL" Decode.string))
staticRequest : BackendTask Throwable (List Entry)
staticRequest : BackendTask FatalError (List Entry)
staticRequest =
Env.expect "AIRTABLE_TOKEN"
|> BackendTask.throw

View File

@ -3,7 +3,7 @@ module TableOfContents exposing (..)
import BackendTask exposing (BackendTask)
import BackendTask.File
import Css
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html.Styled exposing (..)
import Html.Styled.Attributes as Attr exposing (css)
import List.Extra
@ -14,8 +14,8 @@ import Tailwind.Utilities as Tw
backendTask :
BackendTask Throwable (List { file | filePath : String, slug : String })
-> BackendTask Throwable (TableOfContents Data)
BackendTask FatalError (List { file | filePath : String, slug : String })
-> BackendTask FatalError (TableOfContents Data)
backendTask docFiles =
docFiles
|> BackendTask.map
@ -32,13 +32,13 @@ backendTask docFiles =
|> BackendTask.resolve
headingsDecoder : String -> String -> BackendTask Throwable (Entry Data)
headingsDecoder : String -> String -> BackendTask FatalError (Entry Data)
headingsDecoder slug rawBody =
rawBody
|> Markdown.Parser.parse
|> Result.mapError (\_ -> Exception.fromString "Markdown parsing error")
|> Result.mapError (\_ -> FatalError.fromString "Markdown parsing error")
|> Result.map gatherHeadings
|> Result.andThen (nameAndTopLevel slug >> Result.mapError Exception.fromString)
|> Result.andThen (nameAndTopLevel slug >> Result.mapError FatalError.fromString)
|> BackendTask.fromResult

View File

@ -2,7 +2,7 @@ module Api exposing (routes)
import ApiRoute exposing (ApiRoute)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.Validation as Validation
@ -23,7 +23,7 @@ import Xml.Decode
routes :
BackendTask Throwable (List Route)
BackendTask FatalError (List Route)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =

View File

@ -1,7 +1,7 @@
module Route.Blog.Slug_ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Pages.Msg
@ -38,7 +38,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed []
@ -47,7 +47,7 @@ type alias Data =
{}
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.succeed {}

View File

@ -2,7 +2,7 @@ module Route.CookieTest exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html.Styled exposing (text)
import Pages.Msg
@ -44,7 +44,7 @@ type alias Data =
{ darkMode : Maybe String }
data : RouteParams -> Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.expectCookie "dark-mode"

View File

@ -2,7 +2,7 @@ module Route.Counter exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html
@ -85,7 +85,7 @@ type alias Data =
{}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed Data

View File

@ -6,7 +6,7 @@ import BackendTask exposing (BackendTask)
import Css
import Effect
import ErrorPage
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.Validation as Validation
@ -102,7 +102,7 @@ sessionOptions =
data :
RouteParams
-> Server.Request.Parser (BackendTask Throwable (Server.Response.Response Data ErrorPage.ErrorPage))
-> Server.Request.Parser (BackendTask FatalError (Server.Response.Response Data ErrorPage.ErrorPage))
data routeParams =
Server.Request.succeed ()
|> Session.withSession sessionOptions
@ -128,7 +128,7 @@ data routeParams =
action :
RouteParams
-> Server.Request.Parser (BackendTask Throwable (Server.Response.Response ActionData ErrorPage.ErrorPage))
-> Server.Request.Parser (BackendTask FatalError (Server.Response.Response ActionData ErrorPage.ErrorPage))
action routeParams =
Server.Request.formData
(form

View File

@ -7,7 +7,7 @@ import BackendTask.Port
import Dict
import Effect
import ErrorPage
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldView as FieldView
@ -94,7 +94,7 @@ type alias ActionData =
data :
RouteParams
-> Server.Request.Parser (BackendTask Throwable (Server.Response.Response Data ErrorPage.ErrorPage))
-> Server.Request.Parser (BackendTask FatalError (Server.Response.Response Data ErrorPage.ErrorPage))
data routeParams =
Server.Request.succeed
(BackendTask.Port.get "getItems"
@ -117,7 +117,7 @@ type Action
action :
RouteParams
-> Server.Request.Parser (BackendTask Throwable (Server.Response.Response ActionData ErrorPage.ErrorPage))
-> Server.Request.Parser (BackendTask FatalError (Server.Response.Response ActionData ErrorPage.ErrorPage))
action routeParams =
Server.Request.formData
forms

View File

@ -3,7 +3,7 @@ module Route.FileData exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import BackendTask.File
import BuildError exposing (BuildError)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled exposing (text)
@ -46,7 +46,7 @@ type alias Data =
}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
"my-json-data.json"
|> BackendTask.File.jsonFile (Decode.field "greeting" Decode.string)

View File

@ -3,7 +3,7 @@ module Route.Form exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Date exposing (Date)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldView
@ -185,7 +185,7 @@ type alias Data =
{}
data : RouteParams -> Parser (BackendTask Throwable (Server.Response.Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Server.Response.Response Data ErrorPage))
data routeParams =
Data
|> Server.Response.render
@ -193,7 +193,7 @@ data routeParams =
|> Request.succeed
action : RouteParams -> Parser (BackendTask Throwable (Server.Response.Response ActionData ErrorPage))
action : RouteParams -> Parser (BackendTask FatalError (Server.Response.Response ActionData ErrorPage))
action routeParams =
Request.formData (form |> Form.initCombined identity)
|> Request.map

View File

@ -3,7 +3,7 @@ module Route.Greet exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (Html)
@ -81,7 +81,7 @@ type alias Data =
}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.map2 (\a b -> Data a b Nothing)

View File

@ -2,7 +2,7 @@ module Route.Hello exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Pages.Msg
@ -45,7 +45,7 @@ type alias Data =
{}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed (BackendTask.succeed (Response.render Data))

View File

@ -3,7 +3,7 @@ module Route.Index exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import BackendTask.File
import BackendTask.Port
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled exposing (a, div, text)
@ -49,7 +49,7 @@ type alias Data =
}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.map2 Data
(BackendTask.File.rawFile "greeting.txt" |> BackendTask.throw)

View File

@ -1,7 +1,7 @@
module Route.Links exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (text)
@ -43,7 +43,7 @@ type alias Data =
()
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -2,7 +2,7 @@ module Route.Login exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldView
@ -51,7 +51,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
action : RouteParams -> Request.Parser (BackendTask Throwable (Response ActionData ErrorPage))
action : RouteParams -> Request.Parser (BackendTask FatalError (Response ActionData ErrorPage))
action routeParams =
Request.formDataWithServerValidation (form |> Form.initCombinedServer identity)
|> MySession.withSession
@ -161,7 +161,7 @@ form =
|> Form.field "name" (Field.text |> Field.required "Required")
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.succeed ()

View File

@ -2,7 +2,7 @@ module Route.Logout exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import MySession
@ -44,7 +44,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
action : RouteParams -> Request.Parser (BackendTask Throwable (Response ActionData ErrorPage))
action : RouteParams -> Request.Parser (BackendTask FatalError (Response ActionData ErrorPage))
action _ =
Request.succeed ()
|> MySession.withSession
@ -61,7 +61,7 @@ type alias Data =
{}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed (BackendTask.succeed (Response.render {}))

View File

@ -3,7 +3,7 @@ module Route.Redirect exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form.FormData exposing (Method(..))
import Head
import Head.Seo as Seo
@ -92,7 +92,7 @@ type alias Data =
{}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.acceptMethod ( Request.Post, [] )

View File

@ -3,7 +3,7 @@ module Route.Test.BasicAuth exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Base64
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html.Styled exposing (div, text)
import Pages.Msg
@ -46,7 +46,7 @@ type alias Data =
}
data : RouteParams -> Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
withBasicAuth
(\{ username, password } ->

View File

@ -4,7 +4,7 @@ import BackendTask exposing (BackendTask)
import BackendTask.File
import BuildError exposing (BuildError)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html.Styled exposing (div, text)
import Pages.Msg
@ -47,7 +47,7 @@ type alias Data =
}
data : RouteParams -> Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed
(BackendTask.succeed Data

View File

@ -2,7 +2,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Html.Styled
import Pages.Flags
@ -76,7 +76,7 @@ subscriptions _ _ =
Sub.none
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -1,7 +1,7 @@
module Site exposing (config)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Pages.Manifest as Manifest
import Route
@ -19,7 +19,7 @@ config =
}
head : BackendTask Throwable (List Head.Tag)
head : BackendTask FatalError (List Head.Tag)
head =
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")

View File

@ -3,7 +3,7 @@ module MySession exposing (..)
import BackendTask exposing (BackendTask)
import BackendTask.Env as Env
import Codec
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Route
import Server.Request exposing (Parser)
import Server.Response exposing (Response)
@ -19,9 +19,9 @@ cookieOptions =
withSession :
(request -> Result Session.NotLoadedReason Session.Session -> BackendTask Throwable ( Session.Session, Response data errorPage ))
(request -> Result Session.NotLoadedReason Session.Session -> BackendTask FatalError ( Session.Session, Response data errorPage ))
-> Parser request
-> Parser (BackendTask Throwable (Response data errorPage))
-> Parser (BackendTask FatalError (Response data errorPage))
withSession =
Session.withSession
{ name = "mysession"
@ -31,9 +31,9 @@ withSession =
withSessionOrRedirect :
(request -> Session.Session -> BackendTask Throwable ( Session.Session, Response data errorPage ))
(request -> Session.Session -> BackendTask FatalError ( Session.Session, Response data errorPage ))
-> Parser request
-> Parser (BackendTask Throwable (Response data errorPage))
-> Parser (BackendTask FatalError (Response data errorPage))
withSessionOrRedirect toRequest handler =
Session.withSession
{ name = "mysession"
@ -53,7 +53,7 @@ withSessionOrRedirect toRequest handler =
handler
secrets : BackendTask Throwable (List String)
secrets : BackendTask FatalError (List String)
secrets =
Env.expect "SESSION_SECRET"
|> BackendTask.throw
@ -61,9 +61,9 @@ secrets =
expectSessionOrRedirect :
(request -> Session.Session -> BackendTask Throwable ( Session.Session, Response data errorPage ))
(request -> Session.Session -> BackendTask FatalError ( Session.Session, Response data errorPage ))
-> Parser request
-> Parser (BackendTask Throwable (Response data errorPage))
-> Parser (BackendTask FatalError (Response data errorPage))
expectSessionOrRedirect toRequest handler =
Session.withSession
{ name = "mysession"

View File

@ -2,15 +2,16 @@ module Test.HttpRequests exposing (all)
import BackendTask exposing (BackendTask)
import BackendTask.Http
import Exception exposing (Exception)
import Expect
import FatalError exposing (FatalError)
import Json.Decode as Decode
import Test exposing (Test)
all : BackendTask error Test
all : BackendTask FatalError Test
all =
[ BackendTask.Http.get "http://httpstat.us/500" (BackendTask.Http.expectWhatever ())
|> BackendTask.mapError .recoverable
|> test "http 500 error"
(\result ->
case result of
@ -27,6 +28,7 @@ all =
Expect.fail "Expected HTTP error, got Ok"
)
, BackendTask.Http.get "http://httpstat.us/404" (BackendTask.Http.expectWhatever ())
|> BackendTask.mapError .recoverable
|> test "http 404 error"
(\result ->
case result of
@ -43,6 +45,7 @@ all =
Expect.fail "Expected HTTP error, got Ok"
)
, BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.field "stargazers_count" Decode.int)
|> BackendTask.mapError .recoverable
|> test "200 JSON"
(\result ->
case result of
@ -53,6 +56,7 @@ all =
Expect.pass
)
, BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.field "this-field-doesn't-exist" Decode.int)
|> BackendTask.mapError .recoverable
|> test "JSON decoding error"
(\result ->
case result of
@ -74,6 +78,7 @@ all =
BackendTask.Http.expectJson
(Decode.field "this-field-doesn't-exist" Decode.int)
}
|> BackendTask.mapError .recoverable
|> test "cache options"
(\result ->
case result of
@ -112,7 +117,7 @@ all =
|> BackendTask.map (Test.describe "BackendTask tests")
test : String -> (Result error data -> Expect.Expectation) -> BackendTask (Exception error) data -> BackendTask noError Test
test : String -> (Result error data -> Expect.Expectation) -> BackendTask error data -> BackendTask noError Test
test name assert task =
task
|> BackendTask.toResult

View File

@ -4,7 +4,7 @@ import BackendTask exposing (BackendTask)
import BackendTask.File
import Css exposing (..)
import Css.Global
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (..)
@ -48,7 +48,7 @@ type alias Data =
String
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.File.rawFile "unsafe-script-tag.txt"
|> BackendTask.throw

View File

@ -1,7 +1,7 @@
module Route.Index exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html exposing (text)
@ -43,7 +43,7 @@ type alias Data =
()
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -2,13 +2,13 @@ module Api exposing (routes)
import ApiRoute
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Route exposing (Route)
routes :
BackendTask Throwable (List Route)
BackendTask FatalError (List Route)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =

View File

@ -2,7 +2,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import BackendTask
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Html.Styled
import Pages.Flags
@ -76,7 +76,7 @@ subscriptions _ _ =
Sub.none
data : BackendTask.BackendTask Throwable Data
data : BackendTask.BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -2,7 +2,7 @@ module Site exposing (config)
import BackendTask exposing (BackendTask)
import Cloudinary
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import MimeType
import Pages.Manifest as Manifest
@ -23,14 +23,14 @@ type alias Data =
}
data : BackendTask.BackendTask Throwable Data
data : BackendTask.BackendTask FatalError Data
data =
BackendTask.map Data
--(StaticFile.request "site-name.txt" StaticFile.body)
(BackendTask.succeed "site-name")
head : BackendTask Throwable (List Head.Tag)
head : BackendTask FatalError (List Head.Tag)
head =
[ Head.metaName "viewport" (Head.raw "width=device-width,initial-scale=1")
, Head.metaName "mobile-web-app-capable" (Head.raw "yes")

View File

@ -3,7 +3,7 @@ module Api exposing (routes)
import ApiRoute exposing (ApiRoute)
import BackendTask exposing (BackendTask)
import BackendTask.Http
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Json.Decode
import Json.Encode
@ -17,7 +17,7 @@ import Site
routes :
BackendTask Throwable (List Route)
BackendTask FatalError (List Route)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =

View File

@ -3,7 +3,7 @@ module Route.BasicAuth exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Base64
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html exposing (div, text)
import Pages.Msg
@ -46,7 +46,7 @@ type alias ActionData =
{}
data : RouteParams -> Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
withBasicAuth
(\{ username, password } ->

View File

@ -2,7 +2,7 @@ module Route.FileUpload exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -47,7 +47,7 @@ type alias ActionData =
{}
data : RouteParams -> Request.Parser (BackendTask Throwable (Server.Response.Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Server.Response.Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.expectMultiPartFormPost

View File

@ -4,7 +4,7 @@ import BackendTask exposing (BackendTask)
import Date exposing (Date)
import Dict exposing (Dict)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldView
@ -179,7 +179,7 @@ type alias Data =
{}
data : RouteParams -> Parser (BackendTask Throwable (Server.Response.Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Server.Response.Response Data ErrorPage))
data routeParams =
Data
|> Server.Response.render
@ -187,7 +187,7 @@ data routeParams =
|> Request.succeed
action : RouteParams -> Parser (BackendTask Throwable (Server.Response.Response ActionData ErrorPage))
action : RouteParams -> Parser (BackendTask FatalError (Server.Response.Response ActionData ErrorPage))
action routeParams =
Request.formData (form |> Form.initCombined identity)
|> Request.map

View File

@ -2,7 +2,7 @@ module Route.FormEvent exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form.FormData exposing (FormData)
import FormDecoder
import Head
@ -87,7 +87,7 @@ type alias ActionData =
{}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed {}

View File

@ -3,7 +3,7 @@ module Route.Greet exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Dict exposing (Dict)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html exposing (Html)
@ -43,7 +43,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.map2 (\a b -> Data a b Nothing)

View File

@ -3,7 +3,7 @@ module Route.Hello exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Fetcher.Signup
import Head
import Head.Seo as Seo
@ -104,7 +104,7 @@ type alias ActionData =
{}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed (BackendTask.succeed (Response.render Data))

View File

@ -3,7 +3,7 @@ module Route.HelloForm exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -81,12 +81,12 @@ type alias ActionData =
{}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed (BackendTask.succeed (Response.render Data))
action : RouteParams -> Request.Parser (BackendTask Throwable (Response ActionData ErrorPage))
action : RouteParams -> Request.Parser (BackendTask FatalError (Response ActionData ErrorPage))
action routeParams =
Request.skip "No action."

View File

@ -2,7 +2,7 @@ module Route.Hex.Hex_ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ColorHelpers
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import RouteBuilder exposing (StatelessRoute, StaticPayload)
@ -41,6 +41,6 @@ toCssVal routeParams =
"#" ++ routeParams.hex
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed []

View File

@ -3,7 +3,7 @@ module Route.Index exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import BackendTask.Env as Env
import BackendTask.Http
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html exposing (..)
@ -47,7 +47,7 @@ type alias ActionData =
{}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.map2 Data
(BackendTask.Http.getJson

View File

@ -2,7 +2,7 @@ module Route.Login exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.Validation as Validation
@ -67,7 +67,7 @@ form =
|> Form.field "name" (Field.text |> Field.required "Required")
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.formData (form |> Form.initCombined identity)

View File

@ -2,7 +2,7 @@ module Route.Named.Color_ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import ColorHelpers
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import RouteBuilder exposing (StatefulRoute, StatelessRoute, StaticPayload)
@ -41,6 +41,6 @@ toCssVal routeParams =
routeParams.color
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed []

View File

@ -3,7 +3,7 @@ module Route.PokedexNumber_ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import BackendTask.Http
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html exposing (..)
@ -40,12 +40,12 @@ route =
|> RouteBuilder.buildNoState { view = view }
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed []
data : RouteParams -> BackendTask Throwable (Response Data ErrorPage)
data : RouteParams -> BackendTask FatalError (Response Data ErrorPage)
data { pokedexNumber } =
let
asNumber : Int
@ -76,7 +76,7 @@ data { pokedexNumber } =
|> BackendTask.map Response.render
get : String -> Decode.Decoder value -> BackendTask (Exception.Exception BackendTask.Http.Error) value
get : String -> Decode.Decoder value -> BackendTask (FatalError.Recoverable BackendTask.Http.Error) value
get url decoder =
BackendTask.Http.getWithOptions
{ url = url

View File

@ -2,7 +2,7 @@ module Route.PortTest exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import BackendTask.Port
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -46,7 +46,7 @@ type alias ActionData =
{}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed Data
|> BackendTask.andMap (BackendTask.Port.get "hello" (Encode.string "Jane") Decode.string |> BackendTask.throw)

View File

@ -1,7 +1,7 @@
module Route.RedirectLinks exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -43,7 +43,7 @@ type alias ActionData =
{}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed {}

View File

@ -2,7 +2,7 @@ module Route.Rgb.Red_.Green_.Blue_ exposing (ActionData, Data, Model, Msg, route
import BackendTask exposing (BackendTask)
import ColorHelpers
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import RouteBuilder exposing (StatefulRoute, StatelessRoute, StaticPayload)
@ -28,7 +28,7 @@ route =
|> RouteBuilder.buildNoState { view = ColorHelpers.view toCssVal }
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed []

View File

@ -3,7 +3,7 @@ module Route.Search exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldView
@ -99,7 +99,7 @@ list =
]
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.formData (form |> Form.initCombined identity)
@ -169,7 +169,7 @@ errorsForField formState field =
|> Html.ul [ Attr.style "color" "red" ]
action : RouteParams -> Request.Parser (BackendTask Throwable (Response ActionData ErrorPage))
action : RouteParams -> Request.Parser (BackendTask FatalError (Response ActionData ErrorPage))
action routeParams =
Request.skip "No action."

View File

@ -3,7 +3,7 @@ module Route.Secret exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import BackendTask.File
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -56,7 +56,7 @@ type alias LoggedInInfo =
}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ Request.expectCookie "username"

View File

@ -4,7 +4,7 @@ import BackendTask exposing (BackendTask)
import Dict
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldView
@ -57,7 +57,7 @@ route =
}
action : RouteParams -> Request.Parser (BackendTask Throwable (Response ActionData ErrorPage))
action : RouteParams -> Request.Parser (BackendTask FatalError (Response ActionData ErrorPage))
action _ =
(Request.formData (form |> Form.initCombined identity)
|> Request.map (Result.mapError (\error -> "Errors"))
@ -214,7 +214,7 @@ type ActionData
}
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed ()
|> MySession.withSession

View File

@ -7,7 +7,7 @@ import Date exposing (Date)
import Dict exposing (Dict)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form
import Form.Field as Field
import Form.FieldStatus as FieldStatus
@ -210,7 +210,7 @@ validateCapitalized string =
( Nothing, [ "Needs to be capitalized" ] )
form : Form.DoneForm String (BackendTask Throwable (Combined String User)) data (List (Html (Pages.Msg.Msg Msg)))
form : Form.DoneForm String (BackendTask FatalError (Combined String User)) data (List (Html (Pages.Msg.Msg Msg)))
form =
Form.init
(\first last username email dob checkin checkout rating password passwordConfirmation comments candidates offers pushNotifications acceptTerms ->
@ -446,7 +446,7 @@ form =
)
isValidDob : Date -> BackendTask Throwable (Maybe String)
isValidDob : Date -> BackendTask FatalError (Maybe String)
isValidDob birthDate =
if birthDate == Date.fromCalendarDate 1969 Time.Jul 20 then
BackendTask.succeed (Just "No way, that's when the moon landing happened!")
@ -545,7 +545,7 @@ route =
}
action : RouteParams -> Parser (BackendTask Throwable (Response ActionData ErrorPage))
action : RouteParams -> Parser (BackendTask FatalError (Response ActionData ErrorPage))
action routeParams =
Request.formDataWithServerValidation (form |> Form.initCombined identity)
|> Request.map
@ -596,7 +596,7 @@ type alias ActionData =
}
data : RouteParams -> Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.oneOf
[ {}

View File

@ -3,7 +3,7 @@ module Route.Time exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Dict exposing (Dict)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -96,7 +96,7 @@ type alias Request =
-- |> BackendTask.map PageServerResponse.RenderPage
data : RouteParams -> Request.Parser (BackendTask Throwable (Response Data ErrorPage))
data : RouteParams -> Request.Parser (BackendTask FatalError (Response Data ErrorPage))
data routeParams =
Request.succeed ()
|> Request.map

View File

@ -2,7 +2,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Html.Attributes as Attr
import Pages.Flags
@ -80,7 +80,7 @@ subscriptions _ _ =
Sub.none
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.succeed ()

View File

@ -1,7 +1,7 @@
module Site exposing (canonicalUrl, config)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Route exposing (Route)
import SiteConfig exposing (SiteConfig)
@ -24,7 +24,7 @@ canonicalUrl =
"https://elm-pages.com"
head : BackendTask Throwable (List Head.Tag)
head : BackendTask FatalError (List Head.Tag)
head =
[ Head.sitemapLink "/sitemap.xml"
]

View File

@ -6,7 +6,7 @@ module ColorHelpers exposing (..)
import BackendTask exposing (BackendTask)
import BackendTask.Http
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html
@ -20,7 +20,7 @@ import Shared
import View exposing (View)
data : routeParams -> BackendTask Throwable (Server.Response.Response Data ErrorPage)
data : routeParams -> BackendTask FatalError (Server.Response.Response Data ErrorPage)
data _ =
BackendTask.Http.getJson "https://elm-pages-pokedex.netlify.app/.netlify/functions/time"
Decode.string

View File

@ -3,7 +3,7 @@ module MySession exposing (..)
import BackendTask exposing (BackendTask)
import BackendTask.Env as Env
import Codec
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Route
import Server.Request exposing (Parser)
import Server.Response exposing (Response)
@ -19,9 +19,9 @@ cookieOptions =
withSession :
(request -> Result Session.NotLoadedReason Session.Session -> BackendTask Throwable ( Session.Session, Response data errorPage ))
(request -> Result Session.NotLoadedReason Session.Session -> BackendTask FatalError ( Session.Session, Response data errorPage ))
-> Parser request
-> Parser (BackendTask Throwable (Response data errorPage))
-> Parser (BackendTask FatalError (Response data errorPage))
withSession =
Session.withSession
{ name = "mysession"
@ -31,9 +31,9 @@ withSession =
withSessionOrRedirect :
(request -> Session.Session -> BackendTask Throwable ( Session.Session, Response data errorPage ))
(request -> Session.Session -> BackendTask FatalError ( Session.Session, Response data errorPage ))
-> Parser request
-> Parser (BackendTask Throwable (Response data errorPage))
-> Parser (BackendTask FatalError (Response data errorPage))
withSessionOrRedirect toRequest handler =
Session.withSession
{ name = "mysession"
@ -53,7 +53,7 @@ withSessionOrRedirect toRequest handler =
handler
secrets : BackendTask Throwable (List String)
secrets : BackendTask FatalError (List String)
secrets =
Env.expect "SESSION_SECRET"
|> BackendTask.throw
@ -61,9 +61,9 @@ secrets =
expectSessionOrRedirect :
(request -> Session.Session -> BackendTask Throwable ( Session.Session, Response data errorPage ))
(request -> Session.Session -> BackendTask FatalError ( Session.Session, Response data errorPage ))
-> Parser request
-> Parser (BackendTask Throwable (Response data errorPage))
-> Parser (BackendTask FatalError (Response data errorPage))
expectSessionOrRedirect toRequest handler =
Session.withSession
{ name = "mysession"

View File

@ -2,13 +2,13 @@ module Api exposing (routes)
import ApiRoute
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Route exposing (Route)
routes :
BackendTask Throwable (List Route)
BackendTask FatalError (List Route)
-> (Maybe { indent : Int, newLines : Bool } -> Html Never -> String)
-> List (ApiRoute.ApiRoute ApiRoute.Response)
routes getStaticRoutes htmlToString =

View File

@ -1,7 +1,7 @@
module Route.Cats.Name__ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled exposing (text)
@ -39,7 +39,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed
[ { name = Just "larry"
@ -49,7 +49,7 @@ pages =
]
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.succeed {}

View File

@ -1,7 +1,7 @@
module Route.Date.SPLAT_ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html.Styled exposing (text)
import Pages.Msg
@ -39,7 +39,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
pages : BackendTask Throwable (List RouteParams)
pages : BackendTask FatalError (List RouteParams)
pages =
BackendTask.succeed
[ { splat = ( "2021", [ "04", "28" ] )
@ -49,7 +49,7 @@ pages =
]
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.succeed {}

View File

@ -1,7 +1,7 @@
module Route.SPLAT__ exposing (ActionData, Data, Model, Msg, route)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Html.Styled exposing (text)
import Pages.Msg
@ -39,7 +39,7 @@ route =
|> RouteBuilder.buildNoState { view = view }
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.succeed {}

View File

@ -1,7 +1,7 @@
module Route.Slide exposing (ActionData, Data, Model, Msg, route)
import BackendTask
import Exception
import FatalError
import Head
import Head.Seo as Seo
import Pages.Msg

View File

@ -5,7 +5,7 @@ import BackendTask.File
import Browser.Events
import Browser.Navigation
import Effect
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Head.Seo as Seo
import Html.Styled as Html
@ -89,13 +89,13 @@ toDirection string =
Nothing
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.map Data
(slideBody routeParams)
slideBody : RouteParams -> BackendTask Throwable String
slideBody : RouteParams -> BackendTask FatalError String
slideBody route_ =
BackendTask.File.bodyWithoutFrontmatter "slides.md"
|> BackendTask.throw

View File

@ -2,7 +2,7 @@ module Shared exposing (Data, Model, Msg(..), SharedMsg(..), template)
import BackendTask exposing (BackendTask)
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Html.Styled
import Pages.Flags
@ -76,7 +76,7 @@ subscriptions _ _ =
Sub.none
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
--BackendTask.Http.get "https://api.github.com/repos/dillonkearns/elm-pages"
-- (D.field "stargazers_count" D.int)

View File

@ -2,7 +2,7 @@ module Site exposing (config)
import BackendTask exposing (BackendTask)
import Cloudinary
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import MimeType
import Pages.Manifest as Manifest
@ -23,14 +23,14 @@ type alias Data =
}
data : BackendTask Throwable Data
data : BackendTask FatalError Data
data =
BackendTask.map Data
--(StaticFile.request "site-name.txt" StaticFile.body)
(BackendTask.succeed "site-name")
head : BackendTask Throwable (List Head.Tag)
head : BackendTask FatalError (List Head.Tag)
head =
[ Head.icon [ ( 32, 32 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 32)
, Head.icon [ ( 16, 16 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 16)

View File

@ -74,7 +74,7 @@ rule =
finalEvaluation : Context -> List (Rule.Error {})
finalEvaluation context =
case Dict.get [ "Exception" ] context.importContext of
case Dict.get [ "FatalError" ] context.importContext of
Nothing ->
let
importAddRange : { start : { row : Int, column : Int }, end : { row : Int, column : Int } }
@ -86,7 +86,7 @@ finalEvaluation context =
, details = [ "" ]
}
importAddRange
[ Review.Fix.insertAt importAddRange.end "\nimport Exception\n"
[ Review.Fix.insertAt importAddRange.end "\nimport FatalError\n"
]
]
@ -128,7 +128,7 @@ declarationVisitor node context =
exceptionFromString : String
exceptionFromString =
"("
++ referenceFunction context.importContext ( [ "Exception" ], "fromString" )
++ referenceFunction context.importContext ( [ "FatalError" ], "fromString" )
++ " \"\")"
in
case Node.value node of
@ -168,7 +168,7 @@ declarationVisitor node context =
-- TODO need to replace `action` as well
[ ("data = "
++ referenceFunction context.importContext ( [ "BackendTask" ], "fail" )
-- TODO add `import Exception` if not present (and use alias if present)
-- TODO add `import FatalError` if not present (and use alias if present)
++ " "
++ exceptionFromString
++ "\n "
@ -221,7 +221,7 @@ expressionVisitor node context =
exceptionFromString : String
exceptionFromString =
"("
++ referenceFunction context.importContext ( [ "Exception" ], "fromString" )
++ referenceFunction context.importContext ( [ "FatalError" ], "fromString" )
++ " \"\")"
in
[ Rule.errorWithFix

View File

@ -15,7 +15,7 @@ all =
import Server.Request as Request
import BackendTask exposing (BackendTask)
import Exception
import FatalError
import RouteBuilder exposing (Page, StaticPayload, single)
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
@ -70,7 +70,7 @@ data =
import Server.Request as Request
import BackendTask exposing (BackendTask)
import Exception
import FatalError
import RouteBuilder exposing (Page, StaticPayload, single)
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
@ -100,7 +100,7 @@ route : StatelessRoute RouteParams Data ActionData
route =
single
{ head = head
, data = BackendTask.fail (Exception.fromString "")
, data = BackendTask.fail (FatalError.fromString "")
}
|> RouteBuilder.buildNoState { view = view }
@ -115,7 +115,7 @@ data =
"""module Route.Index exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
import BackendTask as DS
import RouteBuilder exposing (Page, StaticPayload, single)
import Pages.PageUrl exposing (PageUrl)
@ -169,7 +169,7 @@ data =
"""module Route.Index exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
import BackendTask as DS
import RouteBuilder exposing (Page, StaticPayload, single)
import Pages.PageUrl exposing (PageUrl)
@ -200,7 +200,7 @@ route : StatelessRoute RouteParams Data ActionData
route =
single
{ head = head
, data = DS.fail (Exception.fromString "")
, data = DS.fail (FatalError.fromString "")
}
|> RouteBuilder.buildNoState { view = view }
@ -217,7 +217,7 @@ data =
import Server.Request as Request
import BackendTask exposing (BackendTask)
import Exception
import FatalError
import RouteBuilder exposing (Page, StaticPayload)
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
@ -272,7 +272,7 @@ data =
import Server.Request as Request
import BackendTask exposing (BackendTask)
import Exception
import FatalError
import RouteBuilder exposing (Page, StaticPayload)
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
@ -301,7 +301,7 @@ type alias Data =
route : StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.preRender
{ data = \\_ -> BackendTask.fail (Exception.fromString "")
{ data = \\_ -> BackendTask.fail (FatalError.fromString "")
, head = head
, pages = pages
}
@ -318,7 +318,7 @@ data =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
type alias Model =
{}
@ -355,7 +355,7 @@ route =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
type alias Model =
{}
@ -390,7 +390,7 @@ route =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
type alias Model =
{}
@ -419,7 +419,7 @@ route =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request
import Exception
import FatalError
type alias Model =
{}
@ -456,7 +456,7 @@ route =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request
import Exception
import FatalError
type alias Model =
{}
@ -491,7 +491,7 @@ route =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request
import Exception
import FatalError
type alias Model =
{}
@ -520,7 +520,7 @@ route =
"""module Route.Login exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
type alias Model =
{}
@ -549,7 +549,7 @@ route =
"""module Route.Index exposing (Data, Model, Msg, route)
import Server.Request as Request
import Exception
import FatalError
import BackendTask exposing (BackendTask)
import RouteBuilder exposing (Page, StaticPayload)
@ -581,7 +581,7 @@ route : StatelessRoute RouteParams Data ActionData
route =
RouteBuilder.single
{ head = head
, data = BackendTask.fail (Exception.fromString "")
, data = BackendTask.fail (FatalError.fromString "")
}
|> RouteBuilder.buildNoState { view = view }
@ -597,7 +597,7 @@ data =
"""module Shared exposing (Data, Model, Msg, template)
import Server.Request as Request
import Exception
import FatalError
import Browser.Navigation
import BackendTask
@ -648,7 +648,7 @@ type alias Model =
"""module Shared exposing (Data, Model, Msg, template)
import Server.Request as Request
import Exception
import FatalError
import Browser.Navigation
import BackendTask
@ -669,7 +669,7 @@ template =
{ init = init
, update = update
, view = view
, data = BackendTask.fail (Exception.fromString "")
, data = BackendTask.fail (FatalError.fromString "")
, subscriptions = subscriptions
, onPageChange = Just OnPageChange
}

View File

@ -89,7 +89,7 @@ import BackendTask exposing (BackendTask)
import Dict exposing (Dict)
import Effect exposing (Effect)
import ErrorPage exposing (ErrorPage)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Http
import Json.Decode
@ -109,9 +109,9 @@ import View exposing (View)
{-| -}
type alias StatefulRoute routeParams data action model msg =
{ data : Json.Decode.Value -> routeParams -> BackendTask Throwable (Server.Response.Response data ErrorPage)
, action : Json.Decode.Value -> routeParams -> BackendTask Throwable (Server.Response.Response action ErrorPage)
, staticRoutes : BackendTask Throwable (List routeParams)
{ data : Json.Decode.Value -> routeParams -> BackendTask FatalError (Server.Response.Response data ErrorPage)
, action : Json.Decode.Value -> routeParams -> BackendTask FatalError (Server.Response.Response action ErrorPage)
, staticRoutes : BackendTask FatalError (List routeParams)
, view :
Maybe PageUrl
-> Shared.Model
@ -124,7 +124,7 @@ type alias StatefulRoute routeParams data action model msg =
, init : Maybe PageUrl -> Shared.Model -> StaticPayload data action routeParams -> ( model, Effect msg )
, update : PageUrl -> StaticPayload data action routeParams -> msg -> model -> Shared.Model -> ( model, Effect msg, Maybe Shared.Msg )
, subscriptions : Maybe PageUrl -> routeParams -> Path -> model -> Shared.Model -> Sub msg
, handleRoute : { moduleName : List String, routePattern : RoutePattern } -> (routeParams -> List ( String, String )) -> routeParams -> BackendTask Throwable (Maybe NotFoundReason)
, handleRoute : { moduleName : List String, routePattern : RoutePattern } -> (routeParams -> List ( String, String )) -> routeParams -> BackendTask FatalError (Maybe NotFoundReason)
, kind : String
, onAction : Maybe (action -> msg)
}
@ -154,9 +154,9 @@ type alias StaticPayload data action routeParams =
{-| -}
type Builder routeParams data action
= WithData
{ data : Json.Decode.Value -> routeParams -> BackendTask Throwable (Server.Response.Response data ErrorPage)
, action : Json.Decode.Value -> routeParams -> BackendTask Throwable (Server.Response.Response action ErrorPage)
, staticRoutes : BackendTask Throwable (List routeParams)
{ data : Json.Decode.Value -> routeParams -> BackendTask FatalError (Server.Response.Response data ErrorPage)
, action : Json.Decode.Value -> routeParams -> BackendTask FatalError (Server.Response.Response action ErrorPage)
, staticRoutes : BackendTask FatalError (List routeParams)
, head :
StaticPayload data action routeParams
-> List Head.Tag
@ -165,7 +165,7 @@ type Builder routeParams data action
{ moduleName : List String, routePattern : RoutePattern }
-> (routeParams -> List ( String, String ))
-> routeParams
-> BackendTask Throwable (Maybe NotFoundReason)
-> BackendTask FatalError (Maybe NotFoundReason)
, kind : String
}
@ -292,14 +292,14 @@ buildWithSharedState config builderState =
{-| -}
single :
{ data : BackendTask Throwable data
{ data : BackendTask FatalError data
, head : StaticPayload data action {} -> List Head.Tag
}
-> Builder {} data action
single { data, head } =
WithData
{ data = \_ _ -> data |> BackendTask.map Server.Response.render
, action = \_ _ -> BackendTask.fail (Exception.fromString "Internal Error - actions should never be called for statically generated pages.")
, action = \_ _ -> BackendTask.fail (FatalError.fromString "Internal Error - actions should never be called for statically generated pages.")
, staticRoutes = BackendTask.succeed [ {} ]
, head = head
, serverless = False
@ -310,15 +310,15 @@ single { data, head } =
{-| -}
preRender :
{ data : routeParams -> BackendTask Throwable data
, pages : BackendTask Throwable (List routeParams)
{ data : routeParams -> BackendTask FatalError data
, pages : BackendTask FatalError (List routeParams)
, head : StaticPayload data action routeParams -> List Head.Tag
}
-> Builder routeParams data action
preRender { data, head, pages } =
WithData
{ data = \_ -> data >> BackendTask.map Server.Response.render
, action = \_ _ -> BackendTask.fail (Exception.fromString "Internal Error - actions should never be called for statically generated pages.")
, action = \_ _ -> BackendTask.fail (FatalError.fromString "Internal Error - actions should never be called for statically generated pages.")
, staticRoutes = pages
, head = head
, serverless = False
@ -348,15 +348,15 @@ preRender { data, head, pages } =
{-| -}
preRenderWithFallback :
{ data : routeParams -> BackendTask Throwable (Server.Response.Response data ErrorPage)
, pages : BackendTask Throwable (List routeParams)
{ data : routeParams -> BackendTask FatalError (Server.Response.Response data ErrorPage)
, pages : BackendTask FatalError (List routeParams)
, head : StaticPayload data action routeParams -> List Head.Tag
}
-> Builder routeParams data action
preRenderWithFallback { data, head, pages } =
WithData
{ data = \_ -> data
, action = \_ _ -> BackendTask.fail (Exception.fromString "Internal Error - actions should never be called for statically generated pages.")
, action = \_ _ -> BackendTask.fail (FatalError.fromString "Internal Error - actions should never be called for statically generated pages.")
, staticRoutes = pages
, head = head
, serverless = False
@ -369,8 +369,8 @@ preRenderWithFallback { data, head, pages } =
{-| -}
serverRender :
{ data : routeParams -> Server.Request.Parser (BackendTask Throwable (Server.Response.Response data ErrorPage))
, action : routeParams -> Server.Request.Parser (BackendTask Throwable (Server.Response.Response action ErrorPage))
{ data : routeParams -> Server.Request.Parser (BackendTask FatalError (Server.Response.Response data ErrorPage))
, action : routeParams -> Server.Request.Parser (BackendTask FatalError (Server.Response.Response action ErrorPage))
, head : StaticPayload data action routeParams -> List Head.Tag
}
-> Builder routeParams data action
@ -386,7 +386,7 @@ serverRender { data, action, head } =
|> Result.mapError Json.Decode.errorToString
|> BackendTask.fromResult
-- TODO include title and better error context and formatting
|> BackendTask.onError (\error -> BackendTask.fail (Exception.fromString error))
|> BackendTask.onError (\error -> BackendTask.fail (FatalError.fromString error))
)
)
|> BackendTask.andThen
@ -397,7 +397,7 @@ serverRender { data, action, head } =
Err error ->
Server.Request.errorsToString error
|> Exception.fromString
|> FatalError.fromString
|> BackendTask.fail
)
, action =
@ -410,7 +410,7 @@ serverRender { data, action, head } =
|> Result.mapError Json.Decode.errorToString
|> BackendTask.fromResult
-- TODO include title and better error context and formatting
|> BackendTask.onError (\error -> BackendTask.fail (Exception.fromString error))
|> BackendTask.onError (\error -> BackendTask.fail (FatalError.fromString error))
)
)
|> BackendTask.andThen
@ -421,7 +421,7 @@ serverRender { data, action, head } =
Err error ->
Server.Request.errorsToString error
|> Exception.fromString
|> FatalError.fromString
|> BackendTask.fail
)
, staticRoutes = BackendTask.succeed []

View File

@ -2,7 +2,7 @@ module SharedTemplate exposing (SharedTemplate)
import BackendTask
import Effect exposing (Effect)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
import Pages.Flags exposing (Flags)
import Pages.PageUrl exposing (PageUrl)
@ -36,7 +36,7 @@ type alias SharedTemplate msg sharedModel sharedData mappedMsg =
-> (msg -> mappedMsg)
-> View mappedMsg
-> { body : List (Html mappedMsg), title : String }
, data : BackendTask.BackendTask Throwable sharedData
, data : BackendTask.BackendTask FatalError sharedData
, subscriptions : Path -> sharedModel -> Sub msg
, onPageChange :
Maybe

View File

@ -1,11 +1,11 @@
module SiteConfig exposing (SiteConfig)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
type alias SiteConfig =
{ canonicalUrl : String
, head : BackendTask Throwable (List Head.Tag)
, head : BackendTask FatalError (List Head.Tag)
}

View File

@ -270,7 +270,7 @@ function generatorWrapperFile(moduleName) {
import Bytes
import BackendTask exposing (BackendTask)
import Exception
import FatalError
import Cli.Program as Program
import Json.Decode as Decode
import Json.Encode as Encode
@ -278,7 +278,7 @@ import Pages.Internal.Platform.GeneratorApplication
import ${moduleName}
main : Program.StatefulProgram Pages.Internal.Platform.GeneratorApplication.Model Pages.Internal.Platform.GeneratorApplication.Msg (BackendTask Exception.Throwable ()) Pages.Internal.Platform.GeneratorApplication.Flags
main : Program.StatefulProgram Pages.Internal.Platform.GeneratorApplication.Model Pages.Internal.Platform.GeneratorApplication.Msg (BackendTask FatalError.FatalError ()) Pages.Internal.Platform.GeneratorApplication.Flags
main =
Pages.Internal.Platform.GeneratorApplication.app
{ data = ${moduleName}.run

View File

@ -2,7 +2,7 @@ module MarkdownCodec exposing (isPlaceholder, noteTitle, titleAndDescription, wi
import BackendTask exposing (BackendTask)
import BackendTask.File as StaticFile
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Extra
import List.Extra
@ -12,7 +12,7 @@ import Markdown.Renderer
import MarkdownExtra
isPlaceholder : String -> BackendTask Throwable (Maybe ())
isPlaceholder : String -> BackendTask FatalError (Maybe ())
isPlaceholder filePath =
filePath
|> StaticFile.bodyWithoutFrontmatter
@ -20,7 +20,7 @@ isPlaceholder filePath =
|> BackendTask.andThen
(\rawContent ->
Markdown.Parser.parse rawContent
|> Result.mapError (\_ -> Exception.fromString "Markdown error")
|> Result.mapError (\_ -> FatalError.fromString "Markdown error")
|> Result.map
(\blocks ->
List.any
@ -47,7 +47,7 @@ isPlaceholder filePath =
)
noteTitle : String -> BackendTask Throwable String
noteTitle : String -> BackendTask FatalError String
noteTitle filePath =
titleFromFrontmatter filePath
|> BackendTask.andThen
@ -78,14 +78,14 @@ noteTitle filePath =
(Result.fromMaybe <|
("Expected to find an H1 heading for page " ++ filePath)
)
|> Result.mapError Exception.fromString
|> Result.mapError FatalError.fromString
|> BackendTask.fromResult
)
)
)
titleAndDescription : String -> BackendTask Throwable { title : String, description : String }
titleAndDescription : String -> BackendTask FatalError { title : String, description : String }
titleAndDescription filePath =
filePath
|> StaticFile.onlyFrontmatter
@ -130,7 +130,7 @@ titleAndDescription filePath =
)
)
|> Result.andThen (Result.fromMaybe <| "Expected to find an H1 heading for page " ++ filePath)
|> Result.mapError Exception.fromString
|> Result.mapError FatalError.fromString
|> BackendTask.fromResult
)
)
@ -166,7 +166,7 @@ findDescription blocks =
|> Maybe.withDefault ""
titleFromFrontmatter : String -> BackendTask Throwable (Maybe String)
titleFromFrontmatter : String -> BackendTask FatalError (Maybe String)
titleFromFrontmatter filePath =
StaticFile.onlyFrontmatter
(Json.Decode.Extra.optionalField "title" Decode.string)
@ -177,7 +177,7 @@ titleFromFrontmatter filePath =
withoutFrontmatter :
Markdown.Renderer.Renderer view
-> String
-> BackendTask Throwable (List Block)
-> BackendTask FatalError (List Block)
withoutFrontmatter renderer filePath =
(filePath
|> StaticFile.bodyWithoutFrontmatter
@ -186,7 +186,7 @@ withoutFrontmatter renderer filePath =
(\rawBody ->
rawBody
|> Markdown.Parser.parse
|> Result.mapError (\_ -> Exception.fromString "Couldn't parse markdown.")
|> Result.mapError (\_ -> FatalError.fromString "Couldn't parse markdown.")
|> BackendTask.fromResult
)
)
@ -197,7 +197,7 @@ withoutFrontmatter renderer filePath =
-- we don't want to encode the HTML since it contains functions so it's not serializable
-- but we can at least make sure there are no errors turning it into HTML before encoding it
|> Result.map (\_ -> blocks)
|> Result.mapError (\error -> Exception.fromString error)
|> Result.mapError (\error -> FatalError.fromString error)
|> BackendTask.fromResult
)
@ -207,7 +207,7 @@ withFrontmatter :
-> Decoder frontmatter
-> Markdown.Renderer.Renderer view
-> String
-> BackendTask Throwable value
-> BackendTask FatalError value
withFrontmatter constructor frontmatterDecoder_ renderer filePath =
BackendTask.map2 constructor
(StaticFile.onlyFrontmatter
@ -222,7 +222,7 @@ withFrontmatter constructor frontmatterDecoder_ renderer filePath =
(\rawBody ->
rawBody
|> Markdown.Parser.parse
|> Result.mapError (\_ -> Exception.fromString "Couldn't parse markdown.")
|> Result.mapError (\_ -> FatalError.fromString "Couldn't parse markdown.")
|> BackendTask.fromResult
)
|> BackendTask.andThen
@ -232,7 +232,7 @@ withFrontmatter constructor frontmatterDecoder_ renderer filePath =
-- we don't want to encode the HTML since it contains functions so it's not serializable
-- but we can at least make sure there are no errors turning it into HTML before encoding it
|> Result.map (\_ -> blocks)
|> Result.mapError (\error -> Exception.fromString error)
|> Result.mapError (\error -> FatalError.fromString error)
|> BackendTask.fromResult
)
)

View File

@ -173,7 +173,7 @@ You define your ApiRoute's in `app/Api.elm`. Here's a simple example:
-}
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Internal.ApiRoute exposing (ApiRoute(..), ApiRouteBuilder(..))
import Json.Decode as Decode
@ -192,14 +192,14 @@ type alias ApiRoute response =
{-| Same as [`preRender`](#preRender), but for an ApiRoute that has no dynamic segments. This is just a bit simpler because
since there are no dynamic segments, you don't need to provide a BackendTask with the list of dynamic segments to pre-render because there is only a single possible route.
-}
single : ApiRouteBuilder (BackendTask Throwable String) (List String) -> ApiRoute Response
single : ApiRouteBuilder (BackendTask FatalError String) (List String) -> ApiRoute Response
single handler =
handler
|> preRender (\constructor -> BackendTask.succeed [ constructor ])
{-| -}
serverRender : ApiRouteBuilder (Server.Request.Parser (BackendTask Throwable (Server.Response.Response Never Never))) constructor -> ApiRoute Response
serverRender : ApiRouteBuilder (Server.Request.Parser (BackendTask FatalError (Server.Response.Response Never Never))) constructor -> ApiRoute Response
serverRender ((ApiRouteBuilder patterns pattern _ _ _) as fullHandler) =
ApiRoute
{ regex = Regex.fromString ("^" ++ pattern ++ "$") |> Maybe.withDefault Regex.never
@ -218,7 +218,7 @@ serverRender ((ApiRouteBuilder patterns pattern _ _ _) as fullHandler) =
|> BackendTask.onError
(\stringError ->
-- TODO make error with title and better context/formatting
Exception.fromString stringError |> BackendTask.fail
FatalError.fromString stringError |> BackendTask.fail
)
|> BackendTask.andThen
(\rendered ->
@ -260,10 +260,10 @@ serverRender ((ApiRouteBuilder patterns pattern _ _ _) as fullHandler) =
{-| -}
preRenderWithFallback : (constructor -> BackendTask Throwable (List (List String))) -> ApiRouteBuilder (BackendTask Throwable (Server.Response.Response Never Never)) constructor -> ApiRoute Response
preRenderWithFallback : (constructor -> BackendTask FatalError (List (List String))) -> ApiRouteBuilder (BackendTask FatalError (Server.Response.Response Never Never)) constructor -> ApiRoute Response
preRenderWithFallback buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) =
let
buildTimeRoutes__ : BackendTask Throwable (List String)
buildTimeRoutes__ : BackendTask FatalError (List String)
buildTimeRoutes__ =
buildUrls (constructor [])
|> BackendTask.map (List.map toString)
@ -302,15 +302,15 @@ encodeStaticFileBody fileBody =
{-| -}
preRender : (constructor -> BackendTask Throwable (List (List String))) -> ApiRouteBuilder (BackendTask Throwable String) constructor -> ApiRoute Response
preRender : (constructor -> BackendTask FatalError (List (List String))) -> ApiRouteBuilder (BackendTask FatalError String) constructor -> ApiRoute Response
preRender buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) as fullHandler) =
let
buildTimeRoutes__ : BackendTask Throwable (List String)
buildTimeRoutes__ : BackendTask FatalError (List String)
buildTimeRoutes__ =
buildUrls (constructor [])
|> BackendTask.map (List.map toString)
preBuiltMatches : BackendTask Throwable (List (List String))
preBuiltMatches : BackendTask FatalError (List (List String))
preBuiltMatches =
buildUrls (constructor [])
in
@ -323,7 +323,7 @@ preRender buildUrls ((ApiRouteBuilder patterns pattern _ toString constructor) a
matches =
Internal.ApiRoute.pathToMatches path fullHandler
routeFound : BackendTask Throwable Bool
routeFound : BackendTask FatalError Bool
routeFound =
preBuiltMatches
|> BackendTask.map (List.member matches)
@ -431,19 +431,19 @@ capture (ApiRouteBuilder patterns pattern previousHandler toString constructor)
{-| For internal use by generated code. Not so useful in user-land.
-}
getBuildTimeRoutes : ApiRoute response -> BackendTask Throwable (List String)
getBuildTimeRoutes : ApiRoute response -> BackendTask FatalError (List String)
getBuildTimeRoutes (ApiRoute handler) =
handler.buildTimeRoutes
{-| Include head tags on every page's HTML.
-}
withGlobalHeadTags : BackendTask Throwable (List Head.Tag) -> ApiRoute response -> ApiRoute response
withGlobalHeadTags : BackendTask FatalError (List Head.Tag) -> ApiRoute response -> ApiRoute response
withGlobalHeadTags globalHeadTags (ApiRoute handler) =
ApiRoute { handler | globalHeadTags = Just globalHeadTags }
{-| -}
getGlobalHeadTagsBackendTask : ApiRoute response -> Maybe (BackendTask Throwable (List Head.Tag))
getGlobalHeadTagsBackendTask : ApiRoute response -> Maybe (BackendTask FatalError (List Head.Tag))
getGlobalHeadTagsBackendTask (ApiRoute handler) =
handler.globalHeadTags

View File

@ -5,7 +5,7 @@ module BackendTask exposing
, andThen, resolve, combine
, andMap
, map2, map3, map4, map5, map6, map7, map8, map9
, catch, throw, mapError, onError, toResult
, throw, mapError, onError, toResult
)
{-| In an `elm-pages` app, each Route Module can define a value `data` which is a `BackendTask` that will be resolved **before** `init` is called. That means it is also available
@ -80,13 +80,13 @@ Any place in your `elm-pages` app where the framework lets you pass in a value o
@docs map2, map3, map4, map5, map6, map7, map8, map9
## Exception Handling
## FatalError Handling
@docs catch, throw, mapError, onError, toResult
@docs throw, mapError, onError, toResult
-}
import Exception exposing (Exception(..), Throwable)
import FatalError exposing (FatalError)
import Json.Encode
import Pages.StaticHttpRequest exposing (RawRequest(..))
@ -524,28 +524,14 @@ map9 combineFn request1 request2 request3 request4 request5 request6 request7 re
{-| -}
catch : BackendTask (Exception error) value -> BackendTask error value
catch ds =
ds
|> onError
(\exception ->
case exception of
Exception error _ ->
fail error
)
{-| -}
throw : BackendTask (Exception error) data -> BackendTask Throwable data
throw : BackendTask { error | fatal : FatalError } data -> BackendTask FatalError data
throw backendTask =
backendTask
|> onError (Exception.throw >> fail)
mapError .fatal backendTask
{-| -}
toResult : BackendTask (Exception error) data -> BackendTask noError (Result error data)
toResult : BackendTask error data -> BackendTask noError (Result error data)
toResult backendTask =
backendTask
|> catch
|> andThen (Ok >> succeed)
|> onError (Err >> succeed)

View File

@ -8,14 +8,14 @@ down into the final `Data` value, it won't end up in the client!
import BackendTask exposing (BackendTask)
import BackendTask.Env
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
type alias EnvVariables =
{ sendGridKey : String
, siteUrl : String
}
sendEmail : Email -> BackendTask Throwable ()
sendEmail : Email -> BackendTask FatalError ()
sendEmail email =
BackendTask.map2 EnvVariables
(BackendTask.Env.expect "SEND_GRID_KEY" |> BackendTask.throw)
@ -24,7 +24,7 @@ down into the final `Data` value, it won't end up in the client!
)
|> BackendTask.andThen (sendEmailBackendTask email)
sendEmailBackendTask : Email -> EnvVariables -> BackendTask Throwable ()
sendEmailBackendTask : Email -> EnvVariables -> BackendTask FatalError ()
sendEmailBackendTask email envVariables =
Debug.todo "Not defined here"
@ -40,7 +40,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 (Exception)
import FatalError exposing (FatalError)
import Json.Decode as Decode
import Json.Encode as Encode
import TerminalText
@ -65,9 +65,9 @@ get envVariableName =
}
{-| Get an environment variable, or a BackendTask Exception if there is no environment variable matching that name.
{-| Get an environment variable, or a BackendTask FatalError if there is no environment variable matching that name.
-}
expect : String -> BackendTask (Exception Error) String
expect : String -> BackendTask { fatal : FatalError, recoverable : Error } String
expect envVariableName =
envVariableName
|> get
@ -75,7 +75,7 @@ expect envVariableName =
(\maybeValue ->
maybeValue
|> Result.fromMaybe
(Exception.Exception (MissingEnvVariable envVariableName)
{ fatal =
{ title = "Missing Env Variable"
, body =
[ TerminalText.text "BackendTask.Env.expect was expecting a variable `"
@ -84,6 +84,7 @@ expect envVariableName =
]
|> TerminalText.toString
}
)
, recoverable = MissingEnvVariable envVariableName
}
|> BackendTask.fromResult
)

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

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 (Exception, Throwable)
import FatalError exposing (FatalError, Recoverable)
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 (Exception String) a
expectUniqueMatch : Glob a -> BackendTask (Recoverable String) a
expectUniqueMatch glob =
glob
|> toBackendTask
@ -1066,13 +1066,13 @@ expectUniqueMatch glob =
[] ->
BackendTask.fail <|
Exception.fromStringWithValue
FatalError.fromStringWithValue
("No files matched the pattern: " ++ toPatternString glob)
("No files matched the pattern: " ++ toPatternString glob)
_ ->
BackendTask.fail <|
Exception.fromStringWithValue
FatalError.fromStringWithValue
"More than one file matched."
"More than one file matched."
)

View File

@ -104,7 +104,7 @@ import Base64
import Bytes exposing (Bytes)
import Bytes.Decode
import Dict exposing (Dict)
import Exception exposing (Exception)
import FatalError exposing (FatalError, Recoverable)
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 (Exception)
import FatalError exposing (FatalError)
import Json.Decode as Decode exposing (Decoder)
getRequest : BackendTask (Exception Error) Int
getRequest : BackendTask (FatalError 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 (Exception Error) a
-> BackendTask (Recoverable 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 (Exception)
import FatalError exposing (FatalError)
getRequest : BackendTask (Exception Error) String
getRequest : BackendTask (FatalError 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 (Exception Error) a
-> BackendTask { fatal : FatalError, recoverable : Error } a
get url expect =
getWithOptions
{ url = url
@ -231,7 +231,7 @@ getWithOptions :
, timeoutInMs : Maybe Int
, cachePath : Maybe String
}
-> BackendTask (Exception Error) a
-> BackendTask (Recoverable Error) a
getWithOptions request__ =
let
request_ : HashRequest.Request
@ -258,7 +258,7 @@ post :
String
-> Body
-> Expect a
-> BackendTask (Exception Error) a
-> BackendTask (Recoverable Error) a
post url body expect =
request
{ url = url
@ -397,7 +397,7 @@ request :
, timeoutInMs : Maybe Int
}
-> Expect a
-> BackendTask (Exception Error) a
-> BackendTask (Recoverable 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 (Exception Error) a
-> BackendTask (Recoverable Error) a
requestRaw request__ expect =
let
request_ : HashRequest.Request
@ -573,7 +573,7 @@ requestRaw request__ expect =
|> BackendTask.fromResult
|> BackendTask.mapError
(\error ->
Exception.Exception error (errorToString error)
FatalError.Recoverable (errorToString error) error
)
)

View File

@ -14,15 +14,15 @@ A `BackendTask.Port` will call an async JavaScript function with the given name
@docs get
Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or an `Exception BackendTask.Port.Error` if it isn't found). In this example,
we're using `BackendTask.throw` to let the framework treat that as an unexpected exception, but we could also handle the possible failures of the `Exception` (see [`Exception`](Exception)).
Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or an `FatalError BackendTask.Port.Error` if it isn't found). In this example,
we're using `BackendTask.throw` to let the framework treat that as an unexpected exception, but we could also handle the possible failures of the `FatalError` (see [`FatalError`](FatalError)).
import BackendTask exposing (BackendTask)
import BackendTask.Port
import Json.Encode
import OptimizedDecoder as Decode
data : BackendTask Throwable String
data : BackendTask FatalError String
data =
BackendTask.Port.get "environmentVariable"
(Json.Encode.string "EDITOR")
@ -78,14 +78,18 @@ to handle possible errors, but you can throw a JSON value and handle it in Elm i
import BackendTask
import BackendTask.Http
import BackendTask.Internal.Request
import Exception exposing (Exception)
import FatalError exposing (FatalError, Recoverable)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import TerminalText
{-| -}
get : String -> Encode.Value -> Decoder b -> BackendTask.BackendTask (Exception Error) b
get :
String
-> Encode.Value
-> Decoder b
-> BackendTask.BackendTask { fatal : FatalError, recoverable : Error } b
get portName input decoder =
BackendTask.Internal.Request.request
{ name = "port"
@ -101,7 +105,7 @@ get portName input decoder =
|> Decode.andThen
(\errorKind ->
if errorKind == "PortNotDefined" then
Exception.Exception (PortNotDefined { name = portName })
{ fatal =
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I expected to find a port named `"
@ -110,6 +114,8 @@ get portName input decoder =
]
|> TerminalText.toString
}
, recoverable = PortNotDefined { name = portName }
}
|> Decode.succeed
else if errorKind == "ExportIsNotFunction" then
@ -118,7 +124,7 @@ get portName input decoder =
|> Decode.map (Maybe.withDefault "")
|> Decode.map
(\incorrectPortType ->
Exception.Exception ExportIsNotFunction
FatalError.Recoverable
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I found an export called `"
@ -128,16 +134,18 @@ get portName input decoder =
]
|> TerminalText.toString
}
ExportIsNotFunction
)
else if errorKind == "MissingPortsFile" then
Exception.Exception MissingPortsFile
FatalError.Recoverable
{ 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."
]
|> TerminalText.toString
}
MissingPortsFile
|> Decode.succeed
else if errorKind == "ErrorInPortsFile" then
@ -146,8 +154,7 @@ get portName input decoder =
|> Decode.map (Maybe.withDefault "")
|> Decode.map
(\errorMessage ->
Exception.Exception
ErrorInPortsFile
FatalError.Recoverable
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I couldn't import the port definitions file, because of this exception:\n\n"
@ -156,6 +163,7 @@ get portName input decoder =
]
|> TerminalText.toString
}
ErrorInPortsFile
)
else if errorKind == "PortCallException" then
@ -164,8 +172,7 @@ get portName input decoder =
|> Decode.map (Maybe.withDefault Encode.null)
|> Decode.map
(\portCallError ->
Exception.Exception
(PortCallException portCallError)
FatalError.Recoverable
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I was able to import the port definitions file, but when running it I encountered this exception:\n\n"
@ -174,10 +181,11 @@ get portName input decoder =
]
|> TerminalText.toString
}
(PortCallException portCallError)
)
else
Exception.Exception ErrorInPortsFile
FatalError.Recoverable
{ title = "Port Error"
, body =
[ TerminalText.text "Something went wrong in a call to BackendTask.Port.get. I expected to find a port named `"
@ -186,6 +194,7 @@ get portName input decoder =
]
|> TerminalText.toString
}
ErrorInPortsFile
|> Decode.succeed
)
|> Decode.map Err

View File

@ -1,13 +1,16 @@
module Exception exposing (Throwable, Exception(..), fromString, fromStringWithValue, throw, unwrap)
module FatalError exposing
( FatalError, fromString, fromStringWithValue, discardValue
, Recoverable
)
{-| The Elm language doesn't have the concept of exceptions or special control flow for errors. It just has
Custom Types, and by convention types like `Result` and the `Err` variant are used to represent possible failure states
and combine together different error states.
`elm-pages` doesn't change that, Elm still doesn't have special exception control flow at the language level. It does have
a type, which is just a regular old Elm type, called `Exception`. Why? Because this plain old Elm type does have one
a type, which is just a regular old Elm type, called `FatalError`. Why? Because this plain old Elm type does have one
special characteristic - the `elm-pages` framework knows how to turn it into an error message. This becomes interesting
because an `elm-pages` app has several places that accept a value of type `BackendTask Exception.Throwable value`.
because an `elm-pages` app has several places that accept a value of type `BackendTask FatalError.FatalError value`.
This design lets the `elm-pages` framework do some of the work for you.
For example, if you wanted to handle possible errors to present them to the user
@ -15,20 +18,20 @@ For example, if you wanted to handle possible errors to present them to the user
type alias Data =
String
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages"
(Decode.field "description" Decode.string)
|> BackendTask.onError
(\error ->
case Exception.unwrap error of
case FatalError.unwrap error of
BackendTask.Http.BadStatus metadata string ->
if metadata.statusCode == 401 || metadata.statusCode == 403 || metadata.statusCode == 404 then
BackendTask.succeed "Either this repo doesn't exist or you don't have access to it."
else
-- we're only handling these expected error cases. In the case of an HTTP timeout,
-- we'll let the error propagate as a Throwable
-- we'll let the error propagate as a FatalError
BackendTask.fail error |> BackendTask.throw
_ ->
@ -38,7 +41,7 @@ For example, if you wanted to handle possible errors to present them to the user
This can be a lot of work for all possible errors, though. If you don't expect this kind of error (it's an _exceptional_ case),
you can let the framework handle it if the error ever does unexpectedly occur.
data : RouteParams -> BackendTask Throwable Data
data : RouteParams -> BackendTask FatalError Data
data routeParams =
BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages"
(Decode.field "description" Decode.string)
@ -54,42 +57,42 @@ issue.
In the case of server-rendered Routes (`RouteBuilder.serverRender`), `elm-pages` will show your 500 error page
when these errors occur.
@docs Throwable, Exception, fromString, fromStringWithValue, throw, unwrap
@docs FatalError, fromString, fromStringWithValue, discardValue
@docs Recoverable
-}
{-| -}
type alias Throwable =
Exception ()
type alias Recoverable error =
{ fatal : FatalError
, recoverable : error
}
{-| -}
type Exception error
= Exception error { title : String, body : String }
type alias FatalError =
{ title : String, body : String }
{-| -}
fromString : String -> Exception ()
fromString : String -> FatalError
fromString string =
fromStringWithValue string ()
{ title = "Custom Error"
, body = string
}
{-| -}
fromStringWithValue : String -> value -> Exception value
fromStringWithValue : String -> value -> Recoverable value
fromStringWithValue string value =
Exception value { title = "Custom Error", body = string }
{ fatal = { title = "Custom Error", body = string }
, recoverable = value
}
{-| -}
throw : Exception error -> Exception ()
throw exception =
case exception of
Exception _ string ->
Exception () string
{-| -}
unwrap : Exception error -> error
unwrap (Exception error _) =
error
discardValue : { other | message : FatalError } -> { message : FatalError }
discardValue record =
{ message = record.message }

View File

@ -269,7 +269,7 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
import BackendTask exposing (BackendTask)
import Dict exposing (Dict)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Form.Field as Field exposing (Field(..))
import Form.FieldStatus as FieldStatus exposing (FieldStatus)
import Form.FieldView
@ -682,7 +682,7 @@ toServerForm :
->
Form
error
{ combine : Validation.Validation error (BackendTask Throwable (Validation.Validation error combined kind constraints)) kind constraints
{ combine : Validation.Validation error (BackendTask FatalError (Validation.Validation error combined kind constraints)) kind constraints
, view : viewFn
}
data
@ -695,7 +695,7 @@ toServerForm (Form a b c) =
{ result : Dict String (List error)
, isMatchCandidate : Bool
, combineAndView :
{ combine : Validation.Validation error (BackendTask Throwable (Validation.Validation error combined kind constraints)) kind constraints
{ combine : Validation.Validation error (BackendTask FatalError (Validation.Validation error combined kind constraints)) kind constraints
, view : viewFn
}
}

View File

@ -9,7 +9,7 @@ module Internal.ApiRoute exposing
)
import BackendTask exposing (BackendTask)
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head
import Json.Decode
import Pattern exposing (Pattern)
@ -46,12 +46,12 @@ tryMatchDone path (ApiRoute handler) =
type ApiRoute response
= ApiRoute
{ regex : Regex
, matchesToResponse : Json.Decode.Value -> String -> BackendTask Throwable (Maybe response)
, buildTimeRoutes : BackendTask Throwable (List String)
, handleRoute : String -> BackendTask Throwable Bool
, matchesToResponse : Json.Decode.Value -> String -> BackendTask FatalError (Maybe response)
, buildTimeRoutes : BackendTask FatalError (List String)
, handleRoute : String -> BackendTask FatalError Bool
, pattern : Pattern
, kind : String
, globalHeadTags : Maybe (BackendTask Throwable (List Head.Tag))
, globalHeadTags : Maybe (BackendTask FatalError (List Head.Tag))
}

View File

@ -1409,6 +1409,6 @@ throwableTask : Elm.Annotation.Annotation -> Elm.Annotation.Annotation
throwableTask dataType =
Elm.Annotation.namedWith [ "BackendTask" ]
"BackendTask"
[ Elm.Annotation.named [ "Exception" ] "Throwable"
[ Elm.Annotation.named [ "FatalError" ] "FatalError"
, dataType
]

View File

@ -12,7 +12,7 @@ import Bytes exposing (Bytes)
import Bytes.Encode
import Codec
import Dict
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Head exposing (Tag)
import Html exposing (Html)
import HtmlPrinter
@ -51,7 +51,7 @@ currentCompatibilityKey =
{-| -}
type alias Model route =
{ staticResponses : BackendTask Throwable Effect
{ staticResponses : BackendTask FatalError Effect
, errors : List BuildError
, maybeRequestJson : RenderRequest route
, isDevServer : Bool
@ -376,11 +376,11 @@ initLegacy :
-> ( Model route, Effect )
initLegacy site ((RenderRequest.SinglePage includeHtml singleRequest _) as renderRequest) { isDevServer } config =
let
globalHeadTags : BackendTask Throwable (List Tag)
globalHeadTags : BackendTask FatalError (List Tag)
globalHeadTags =
(config.globalHeadTags |> Maybe.withDefault (\_ -> BackendTask.succeed [])) HtmlPrinter.htmlToString
staticResponsesNew : BackendTask Throwable Effect
staticResponsesNew : BackendTask FatalError Effect
staticResponsesNew =
StaticResponses.renderApiRequest
(case singleRequest of

View File

@ -11,7 +11,7 @@ import BuildError exposing (BuildError)
import Cli.Program as Program exposing (FlagsIncludingArgv)
import Codec
import Dict
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import HtmlPrinter
import Json.Decode as Decode
import Json.Encode as Encode
@ -33,7 +33,7 @@ type alias Flags =
{-| -}
type alias Model =
{ staticResponses : BackendTask Throwable ()
{ staticResponses : BackendTask FatalError ()
, errors : List BuildError
}
@ -47,10 +47,10 @@ type Msg
{-| -}
app :
GeneratorProgramConfig
-> Program.StatefulProgram Model Msg (BackendTask Throwable ()) Flags
-> Program.StatefulProgram Model Msg (BackendTask FatalError ()) Flags
app config =
let
cliConfig : Program.Config (BackendTask Throwable ())
cliConfig : Program.Config (BackendTask FatalError ())
cliConfig =
case config.data of
Pages.Internal.Script.Script theCliConfig ->
@ -246,7 +246,7 @@ perform config effect =
{-| -}
init :
BackendTask Throwable ()
BackendTask FatalError ()
-> FlagsIncludingArgv Flags
-> ( Model, Effect )
init execute flags =
@ -282,11 +282,11 @@ init execute flags =
initLegacy :
BackendTask Throwable ()
BackendTask FatalError ()
-> ( Model, Effect )
initLegacy execute =
let
staticResponses : BackendTask Throwable ()
staticResponses : BackendTask FatalError ()
staticResponses =
StaticResponses.renderApiRequest execute

View File

@ -2,7 +2,7 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), empty, ne
import BackendTask exposing (BackendTask)
import BuildError exposing (BuildError)
import Exception exposing (Exception(..), Throwable)
import FatalError exposing (FatalError, Recoverable)
import List.Extra
import Pages.StaticHttp.Request as HashRequest
import Pages.StaticHttpRequest as StaticHttpRequest
@ -10,27 +10,27 @@ import RequestsAndPending exposing (RequestsAndPending)
import TerminalText
empty : a -> BackendTask Throwable a
empty : a -> BackendTask FatalError a
empty a =
BackendTask.succeed a
renderApiRequest :
BackendTask Throwable response
-> BackendTask Throwable response
BackendTask FatalError response
-> BackendTask FatalError response
renderApiRequest request =
request
type NextStep route value
= Continue (List HashRequest.Request) (StaticHttpRequest.RawRequest Throwable value)
= Continue (List HashRequest.Request) (StaticHttpRequest.RawRequest FatalError value)
| Finish value
| FinishedWithErrors (List BuildError)
nextStep :
RequestsAndPending
-> BackendTask Throwable a
-> BackendTask FatalError a
->
{ model
| errors : List BuildError
@ -38,7 +38,7 @@ nextStep :
-> NextStep route a
nextStep allRawResponses staticResponses { errors } =
let
staticRequestsStatus : StaticHttpRequest.Status Throwable a
staticRequestsStatus : StaticHttpRequest.Status FatalError a
staticRequestsStatus =
allRawResponses
|> StaticHttpRequest.cacheRequestResolution staticResponses
@ -63,7 +63,7 @@ nextStep allRawResponses staticResponses { errors } =
StaticHttpRequest.HasPermanentError _ ->
( ( False, Nothing )
, []
, BackendTask.fail (Exception.fromString "TODO this shouldn't happen")
, BackendTask.fail (FatalError.fromString "TODO this shouldn't happen")
)
in
if pendingRequests then
@ -111,7 +111,7 @@ nextStep allRawResponses staticResponses { errors } =
Just (Ok completed) ->
Finish completed
Just (Err (Exception () buildError)) ->
Just (Err buildError) ->
FinishedWithErrors
[ { title = buildError.title |> String.toUpper
, path = "" -- TODO include path here

View File

@ -2,7 +2,7 @@ module Pages.Internal.Script exposing (Script(..))
import BackendTask exposing (BackendTask)
import Cli.Program as Program
import Exception exposing (Throwable)
import FatalError exposing (FatalError)
import Html exposing (Html)
@ -13,5 +13,5 @@ type Script
-> Html Never
-> String
)
-> Program.Config (BackendTask Throwable ())
-> Program.Config (BackendTask FatalError ())
)

Some files were not shown because too many files have changed in this diff Show More