dillonkearns / elm-pages-starter

Starter blog for elm-pages

Home Page:https://elm-pages-starter.netlify.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runtime error when blog author is not in Author.elm

MMesch opened this issue · comments

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?

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:

all : List Author
all =
[ { name = "Dillon Kearns"
, avatar = Pages.images.author.dillon
, bio = "Elm developer and educator. Founder of Incremental Elm Consulting."
}
]
decoder : Decoder Author
decoder =
Decode.string
|> Decode.andThen
(\lookupName ->
case List.Extra.find (\currentAuthor -> currentAuthor.name == lookupName) all of
Just author ->
Decode.succeed author
Nothing ->
Decode.fail ("Couldn't find author with name " ++ lookupName ++ ". Options are " ++ String.join ", " (List.map .name all))
)

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

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!

I think this is solved!