dillonkearns / elm-pages-starter

Starter blog for elm-pages
https://elm-pages-starter.netlify.com
95 stars 41 forks source link

Better decode.fail messages #9

Closed Spaxe closed 4 years ago

Spaxe commented 4 years ago

Hello!

I've found it easier in my own project to list all the correct values when I have a typo for the images.

Old message:

ERROR in -- METADATA DECODE ERROR --- elm-pages

I ran into a problem when parsing the metadata for the page with this path: blog/hello

Problem with the value at json.image:

    "images/article-covers/hello.jpeg"

Couldn't find image.

New message:

ERROR in -- METADATA DECODE ERROR --- elm-pages

I ran into a problem when parsing the metadata for the page with this path: blog/hello

Problem with the value at json.image:

    "images/article-covers/hello.jpeg"

I couldn't find that. Available images are:

    "images/article-covers/hello.jpg"
    "images/article-covers/mountains.jpg"
    "images/author/dillon.jpg"
    "images/elm-logo.svg"
    "images/github.svg"
    "images/icon-png.png"
    "images/icon.svg"

Hope you find this useful.

dillonkearns commented 4 years ago

I totally agree. Appreciate the PR, thank you!

Longer term in elm-pages, I've been thinking about having the Err types have accept a custom type rather than a String. Something like:

type ElmPagesBuildError
  = UnexpectedOption { found : String, available : String, additionalInfo : String }
  | -- ...

The type might look a little different, and the API. But the basic idea is that the framework could help with presenting these types of errors more intelligently. For example, using fuzzy matching, showing a limited number of options if the list is too long, formatting with colors, or even a custom HTML presentation depending on the context. Could be interesting!

Anyway, something I've been thinking about! 😄