Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Decoder error message creation #806

Open
Massolari opened this issue Feb 15, 2025 · 3 comments
Open

Bug: Decoder error message creation #806

Massolari opened this issue Feb 15, 2025 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Massolari
Copy link

When trying to decode a nullable field using the wrong code below:

  use link_flair_text <- decode.optional_field(
    "link_flair_text",
    "",
    decode.string,
  )

The error I get is: UnableToDecode([DecodeError("String", "Atom", ["data", "children", "0", "data"])]). The field link_flair_text is, indeed on data.children[0].data, but the message doesn't say the error is on the field link_flair_text

@lpil
Copy link
Member

lpil commented Feb 17, 2025

Oh dear! Thank you!

Could you please share your code and data please so we can replicate and fix the problem.

@Massolari
Copy link
Author

I managed to reproduce it in the Gleam playground. You see that the error message doesn't say that the error is on the field "a"

@lpil
Copy link
Member

lpil commented Feb 18, 2025

Thank you.

import gleam/io
import gleam/dict
import gleam/dynamic
import gleam/dynamic/decode

pub fn main() {
  let data = dict.from_list([
    #("a", Nil)
  ])
  
  let decoder = {
    use bar <- decode.optional_field("a", "", decode.string)
    
    decode.success(bar)
  }
  
  data
  |> dynamic.from
  |> decode.run(decoder)
  |> io.debug
}

@lpil lpil added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants