Ash.Error.Query.NotFound error is now returned as Ash.Error.Invalid?

On 3.4.69 when a get couldn’t find a record i would get {:error, %Ash.Error.Query.NotFound{}

But something changed in 3.4.70 and I now get:

{:error, %Ash.Error.Invalid{
  errors: [
    %Ash.Error.Query.NotFound{
      primary_key: nil,
      resource: MyResource,
      splode: Ash.Error,
      bread_crumbs: [],
      vars: [],
      path: [],
      stacktrace: #Splode.Stacktrace<>,
      class: :invalid
    }
  ]
}}

I have a ton of case pattern matches all over my code expecting the {:error, %Ash.Error.Query.NotFound{} pattern. I don’t see anything in the changelog covering this.

What was the change? I read the weekly updates, did I miss something in that?

This was a bug fix where code interfaces were not using Ash.Error.to_ash_error for all errors, so you’d get inconsistent results from those errors. I don’t know if we called out Ash.Error.Query.NotFound or not, but we should have if we didn’t :sweat: Sorry about this, should have done it with a backwards compatibility flag to make it opt-in.

We can’t add this flag retroactively unfortunately because then its a breaking change for users who have upgraded and made the necessary change, so basically a mistake on our part that we can’t really do anything about now :sweat:

1 Like

No worries! Just glad I had tests to catch it.

I tend to only update ash once a month or less frequently because there is usually some “oh god, what do I need to change now” item. :slight_smile: I don’t know if it is how I use ash, or how updates to ash are coded, but if I didn’t have decent unit test coverage, I’d be in trouble.

And thank you for the new Ash.transaction change. I had this complicated messy one for Ash.DataLayer that I was working on, and it became so much simpler.

this bit me today as well. glad i found this post, all fixed again.

1 Like