dillonkearns / elm-pages-starter

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

Runtime error when blog author is not in Author.elm #6

Closed MMesch closed 4 years ago

MMesch commented 4 years ago

I am just trying out elm-pages. Looks really nice. I thought I'd report a runtime error that I experienced. When elm-pages encounters an author name in the blog that it is not in Author.elm (I changed it to my name), the site crashes - together with the npm start development server:

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

Problem with the value at json.author:

    "Dillon Kearns"

Couldn't find author with name Dillon Kearns. Options are MMesch

Can this be caught?

dillonkearns commented 4 years ago

Hello @MMesch!

Based on the error message, it looks like you just need to either delete the draft.md post, or change the name to your name there:

https://raw.githubusercontent.com/dillonkearns/elm-pages-starter/master/content/blog/draft.md

To give a little background on the mechanics of these error messages, catching errors isn't possible in Elm because Elm doesn't have runtime exceptions (or any exceptions, it only has data types like Result). So there is no special control flow like catch.

The error you're seeing here with a message like I ran into a problem when parsing the metadata in the command line is a build-time error rather than a run-time error. It's coming from this part of the code, so if you wanted the logic to be different, you could simply remove or change that logic. The logic for the author validation comes from this code here:

https://github.com/dillonkearns/elm-pages-starter/blob/20844835c9db2155345892eb5af133f462602f5d/src/Data/Author.elm#L18-L38

I hope that helps! Happy to clarify things more if you have more questions on that.

MMesch commented 4 years ago

Hey Dillon,

thanks for your fast answer.

it looks like you just need to either delete the draft.md post, or change the name to your name there:

yes, I managed to fix it without problem.

The error you're seeing here [...] is a build-time error rather than a run-time error.

I was confused by this. I saw it appearing on the website in the browser (I ran npm start) and not in the console, so I seemed like a Runtime error to me. In itself this is not an issue, but I have read a minute before the phrase "No Runtime errors" about elm and the first thing I have changed seemingly produced one. I just thought that it might be helpful to report my beginner user impression to avoid such misunderstandings as far as possible. But thanks to your explanation I understand it better now!

MMesch commented 4 years ago

I think this is solved!