
Sign up to save your podcasts
Or
Here's an Ellie example that shows the error when you have an implicit type that your flags decode to and it's incorrect.
Sorry Dillon... Jeroen won the trivia challenge this time 😉 It turns out that ports will throw exceptions when they are given a bad value from JavaScript, but it doesn't bring down your Elm app. Elm continues to run with an unhandled exception. Here's an Ellie example.
Flags and ports will never throw a runtime exception in your Elm app if you always use Json.Decode.Values and Json.Encode.Values for them and handle unexpected cases. Flags and ports are the one place that Elm lets you make unsafe assumptions about JSON data.
Benefits of Elm's Approach to JSONNote about Decode.maybe. It can be unsafe to use this function because it can cover up failures.
Json.Decode.Extra.optionalNullableField might have more intuitive and desirable behavior for these cases.
Thank you to lydell for the tip! See the discussion in this discourse thread.
Learning resourceSubmit your question to Elm Radio!
5
1616 ratings
Here's an Ellie example that shows the error when you have an implicit type that your flags decode to and it's incorrect.
Sorry Dillon... Jeroen won the trivia challenge this time 😉 It turns out that ports will throw exceptions when they are given a bad value from JavaScript, but it doesn't bring down your Elm app. Elm continues to run with an unhandled exception. Here's an Ellie example.
Flags and ports will never throw a runtime exception in your Elm app if you always use Json.Decode.Values and Json.Encode.Values for them and handle unexpected cases. Flags and ports are the one place that Elm lets you make unsafe assumptions about JSON data.
Benefits of Elm's Approach to JSONNote about Decode.maybe. It can be unsafe to use this function because it can cover up failures.
Json.Decode.Extra.optionalNullableField might have more intuitive and desirable behavior for these cases.
Thank you to lydell for the tip! See the discussion in this discourse thread.
Learning resourceSubmit your question to Elm Radio!