mirror of
https://github.com/dillonkearns/elm-pages.git
synced 2024-10-26 10:27:36 +03:00
Handle errors in commands.
This commit is contained in:
parent
2e7c5d1bdb
commit
f7d42231d2
@ -37,6 +37,10 @@ run =
|
||||
(\() ->
|
||||
Expect.pass
|
||||
)
|
||||
, Stream.command "does-not-exist" []
|
||||
|> Stream.run
|
||||
|> expectError "command with error"
|
||||
"Error: spawn does-not-exist ENOENT"
|
||||
, BackendTask.Custom.run "hello"
|
||||
Encode.null
|
||||
Decode.string
|
||||
@ -181,7 +185,10 @@ expectError name message task =
|
||||
\() ->
|
||||
case result of
|
||||
Ok data ->
|
||||
Expect.fail "Expected a failure, but got success!"
|
||||
--Expect.fail "Expected a failure, but got success!"
|
||||
result
|
||||
|> Debug.toString
|
||||
|> Expect.equal "Expected a failure, but got success!"
|
||||
|
||||
Err error ->
|
||||
let
|
||||
|
@ -768,7 +768,6 @@ async function pipePartToStream(
|
||||
retry: part.retries,
|
||||
timeout: part.timeoutInMs,
|
||||
});
|
||||
// TODO what if there is an error?
|
||||
let metadata = {
|
||||
headers: Object.fromEntries(response.headers.entries()),
|
||||
statusCode: response.status,
|
||||
@ -799,6 +798,11 @@ async function pipePartToStream(
|
||||
env: env,
|
||||
});
|
||||
|
||||
newProcess.on("error", (error) => {
|
||||
console.error("ERROR!");
|
||||
resolve({ error: error.toString() });
|
||||
});
|
||||
|
||||
lastStream && lastStream.pipe(newProcess.stdin);
|
||||
let newStream;
|
||||
if (output === "MergeWithStdout") {
|
||||
|
@ -272,8 +272,28 @@ run stream =
|
||||
BackendTask.Internal.Request.request
|
||||
{ name = "stream"
|
||||
, body = BackendTask.Http.jsonBody (pipelineEncoder stream "none")
|
||||
, expect = BackendTask.Http.expectJson (Decode.succeed ())
|
||||
, expect =
|
||||
BackendTask.Http.expectJson
|
||||
(Decode.oneOf
|
||||
[ Decode.field "error" Decode.string
|
||||
|> Decode.andThen
|
||||
(\error ->
|
||||
Decode.succeed
|
||||
(Err
|
||||
(FatalError.recoverable
|
||||
{ title = "Stream Error"
|
||||
, body = error
|
||||
}
|
||||
(StreamError error)
|
||||
)
|
||||
)
|
||||
)
|
||||
, Decode.succeed (Ok ())
|
||||
]
|
||||
)
|
||||
}
|
||||
|> BackendTask.andThen BackendTask.fromResult
|
||||
|> BackendTask.allowFatal
|
||||
|
||||
|
||||
pipelineEncoder : Stream error metadata kind -> String -> Encode.Value
|
||||
|
Loading…
Reference in New Issue
Block a user