BytesIssue9DecoderSwallowsExceptionTest
Tags:elm19-bug
Issue: elm/bytes#9
`Bytes.Decode.decode` turns any exception thrown inside a decoder into `Nothing`. <https://github.com/elm/bytes/issues/9> The decoder's `try`/`catch` is meant for reads past the end of the bytes, but in Elm 0.19.1 (elm/bytes 1.0.8) it also catches a crash in user code (a `Debug.todo`, or a stack overflow) in a `map`, and `decode` returns `Nothing` as if the bytes were malformed. The crash must propagate.
Results
elm-0.19.1
failran in 51 msexit code 0, expected 1 --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. decoded: Nothing
elm-0.19.2
failran in 44 msexit code 0, expected 1 --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. decoded: Nothing
elm-0.19.3
failran in 67 msexit code 0, expected 1 --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. decoded: Nothing
lamdera-1.5.0
failran in 65 msexit code 0, expected 1 --- output --- decoded: Nothing
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/BytesIssue9DecoderSwallowsExceptionTest] in its title.
Source
The -- CHECK: lines give the expected output.
module BytesIssue9DecoderSwallowsExceptionTest exposing (main)
{-| `Bytes.Decode.decode` turns any exception thrown inside a decoder into `Nothing`.
<https://github.com/elm/bytes/issues/9>
The decoder's `try`/`catch` is meant for reads past the end of the bytes, but in Elm 0.19.1
(elm/bytes 1.0.8) it also catches a crash in user code (a `Debug.todo`, or a stack overflow) in a
`map`, and `decode` returns `Nothing` as if the bytes were malformed. The crash must propagate.
-}
-- TAGS: elm19-bug
-- EXIT: 1
-- CHECK: boom
-- CHECK-NOT: decoded: Nothing
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode (E.unsignedInt8 1)
_ =
Debug.log "decoded" (D.decode (D.map (\_ -> Debug.todo "boom") D.unsignedInt8) bytes |> Maybe.map (\() -> ()))
in
text "done"