Change generateFiles to return Results so users can make it fail explicitly instead of squelching errors.

This commit is contained in:
Dillon Kearns 2020-01-25 12:47:06 -08:00
parent 194aa06dfb
commit c79d736844
5 changed files with 76 additions and 21 deletions

View File

@ -81,12 +81,14 @@ generateFiles :
}
->
List
{ path : List String
, content : String
}
(Result String
{ path : List String
, content : String
}
)
generateFiles siteMetadata =
[ Feed.fileToGenerate { siteTagline = siteTagline, siteUrl = canonicalSiteUrl } siteMetadata
, MySitemap.build { siteUrl = canonicalSiteUrl } siteMetadata
[ Feed.fileToGenerate { siteTagline = siteTagline, siteUrl = canonicalSiteUrl } siteMetadata |> Ok
, MySitemap.build { siteUrl = canonicalSiteUrl } siteMetadata |> Ok
]

View File

@ -541,9 +541,11 @@ application :
}
->
List
{ path : List String
, content : String
}
(Result String
{ path : List String
, content : String
}
)
, canonicalSiteUrl : String
, pathKey : pathKey
, onPageChange : PagePath pathKey -> userMsg
@ -632,9 +634,11 @@ cliApplication :
}
->
List
{ path : List String
, content : String
}
(Result String
{ path : List String
, content : String
}
)
, canonicalSiteUrl : String
, pathKey : pathKey
, onPageChange : PagePath pathKey -> userMsg

View File

@ -177,9 +177,11 @@ type alias Config pathKey userMsg userModel metadata view =
}
->
List
{ path : List String
, content : String
}
(Result String
{ path : List String
, content : String
}
)
, canonicalSiteUrl : String
, pathKey : pathKey
, onPageChange : PagePath pathKey -> userMsg
@ -797,19 +799,56 @@ sendStaticResponsesIfDone config siteMetadata mode secrets allRawResponses error
}
)
|> config.generateFiles
generatedOkayFiles =
generatedFiles
|> List.filterMap
(\result ->
case result of
Ok ok ->
Just ok
_ ->
Nothing
)
generatedFileErrors =
generatedFiles
|> List.filterMap
(\result ->
case result of
Ok ok ->
Nothing
Err error ->
Just
{ title = "Generate Files Error"
, message =
[ Terminal.text "I encountered an Err in the generateFiles for the path TODO."
, Terminal.text <| "\nError: " ++ error
]
-- List Terminal.Text
}
--Just error
)
allErrors : List BuildError
allErrors =
errors ++ failedRequests ++ generatedFileErrors
in
( updatedAllRawResponses
, SendJsData
(if List.isEmpty errors && List.isEmpty failedRequests then
(if List.isEmpty allErrors then
Success
(ToJsSuccessPayload
(encodeStaticResponses mode staticResponses)
config.manifest
generatedFiles
generatedOkayFiles
)
else
Errors <| BuildError.errorsToString (failedRequests ++ errors)
Errors <| BuildError.errorsToString allErrors
)
)

View File

@ -85,9 +85,11 @@ application :
}
->
List
{ path : List String
, content : String
}
(Result String
{ path : List String
, content : String
}
)
, onPageChange : PagePath pathKey -> userMsg
, canonicalSiteUrl : String
, internals : Pages.Internal.Internal pathKey

View File

@ -564,9 +564,17 @@ start pages =
Debug.todo "Couldn't find page"
}
in
{-
(Model -> model)
-> ContentCache.ContentCache metadata view
-> Result (List BuildError) (List ( PagePath pathKey, metadata ))
-> Config pathKey userMsg userModel metadata view
-> Decode.Value
-> ( model, Effect pathKey )
-}
ProgramTest.createDocument
{ init = Main.init identity contentCache siteMetadata config
, update = Main.update config
, update = Main.update siteMetadata config
, view = \_ -> { title = "", body = [] }
}
|> ProgramTest.withSimulatedEffects simulateEffects