Ash Framework: variable assignment mistake (page 38)

In the “Defining an update action” section
artist = Tunez.Music.get_artist_by_id!(​"​​an-artist-id"​)
should be:
{:ok, artist} = Tunez.Music.get_artist_by_id!(​"​​an-artist-id"​)

Otherwise the next line will fail with an error about resource ID

Hi there!

In this case, no it shouldn’t - the bang version of a function (ie. get_artist_by_id! vs. get_artist_by_id) will return the object by itself, not as part of an ok or error tuple.

I’ll check and see if we need a note clarifying this…

2 Likes

I would caution against it given that this is basic Elixir. If that warrants an explanation then what about explaining pattern matching and “let it crash” ? Those are the reason why we have bang functions.

This looks like a rabbit hole to me.