File read build errors.

This commit is contained in:
Dillon Kearns 2021-04-22 14:53:47 -07:00
parent 4bcfcbd358
commit 4c9c365887
3 changed files with 74 additions and 27 deletions

View File

@ -67,7 +67,7 @@ function runElmApp() {
outputString(fromElm);
} else if (fromElm.tag === "ReadFile") {
const filePath = fromElm.args[0];
try {
const fileContents = fs.readFileSync(filePath).toString();
const parsedFile = matter(fileContents);
app.ports.fromJsPort.send({
@ -79,6 +79,12 @@ function runElmApp() {
rawFile: fileContents,
},
});
} catch (error) {
app.ports.fromJsPort.send({
tag: "BuildError",
data: { filePath },
});
}
} else if (fromElm.tag === "Glob") {
const globPattern = fromElm.args[0];
const globResult = globby.sync(globPattern);

View File

@ -88,7 +88,7 @@ function runElmApp(compiledElmPath, pagePath, request, addDataSourceWatcher) {
}
} else if (fromElm.tag === "ReadFile") {
const filePath = fromElm.args[0];
try {
addDataSourceWatcher(filePath);
const fileContents = (
@ -104,6 +104,12 @@ function runElmApp(compiledElmPath, pagePath, request, addDataSourceWatcher) {
rawFile: fileContents,
},
});
} catch (error) {
app.ports.fromJsPort.send({
tag: "BuildError",
data: { filePath },
});
}
} else if (fromElm.tag === "Glob") {
const globPattern = fromElm.args[0];
addDataSourceWatcher(globPattern);

View File

@ -59,6 +59,7 @@ type alias Model route =
type Msg
= GotStaticHttpResponse { request : { masked : RequestDetails, unmasked : RequestDetails }, response : Result Pages.Http.Error String }
| GotStaticFile ( String, Decode.Value )
| GotBuildError BuildError
| GotGlob ( String, Decode.Value )
| Continue
@ -102,6 +103,23 @@ cliApplication config =
-- tag: "GotGlob"
-- tag: "GotFile"
case tag of
"BuildError" ->
Decode.field "data"
(Decode.field "filePath" Decode.string
|> Decode.map
(\filePath ->
{ title = "File not found"
, message =
[ Terminal.text "A DataSource.File read failed because I couldn't find this file: "
, Terminal.yellow <| Terminal.text filePath
]
, fatal = True
, path = "" -- TODO wire in current path here
}
)
)
|> Decode.map GotBuildError
"GotFile" ->
gotStaticFileDecoder
|> Decode.map GotStaticFile
@ -608,6 +626,23 @@ update contentCache config msg model =
Nothing
|> nextStepToEffect contentCache config updatedModel
GotBuildError buildError ->
let
updatedModel =
{ model
| errors =
buildError :: model.errors
}
in
StaticResponses.nextStep config
updatedModel.mode
updatedModel.secrets
updatedModel.allRawResponses
updatedModel.errors
updatedModel.staticResponses
Nothing
|> nextStepToEffect contentCache config updatedModel
nextStepToEffect :
ContentCache