update/destroy on a missing id returns error class "unknown", while get returns "invalid"

Open Beginner friendly
#24 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
elixir

Research direction

Start with AshLua.Runtime.unwrap_bulk_result/3 in lib/ash_lua/runtime.ex and AshLua.Encoder.error_class/1 in lib/ash_lua/encoder.ex, then trace how get encodes the same NotFound error. Convert or classify the bulk error consistently so missing IDs from update and destroy report class "invalid" like get; verify all three operations return the same class.

Written by the indexing model from the issue text.

Description

Seen on 0.2.3 and still on main (878d144e).

A get on an id that doesn't exist returns an error whose class is "invalid". An update or destroy on an id that doesn't exist returns class == "unknown". A script that branches on err.class therefore treats the same "not found" in two different ways.

Cause

AshLua.Runtime.unwrap_bulk_result/3 (lib/ash_lua/runtime.ex ~1180-1194) returns a bare Ash.Error.Query.NotFound for an empty :success bulk result. Its error branch can also return a list of errors. AshLua.Encoder.error_class/1 (lib/ash_lua/encoder.ex ~472-477) only matches the top-level error-class structs (Ash.Error.Invalid, Forbidden, …), so the bare NotFound falls through to "unknown".

Repro
  1. Take any resource with an update action exposed on the Lua surface.
  2. Run local ok, err = x.update({ input = { id = "<a uuid that does not exist>", ... } }).
  3. err.class is "unknown", while x.get with the same id gives "invalid".
Suggested fix

Run the error through Ash.Error.to_error_class/1 in encode_error/1 (or in unwrap_bulk_result/3) before classifying it. NotFound then becomes an Ash.Error.Invalid (class "invalid"), the same as get.

Dominant language
Elixir
Stars
15
Forks
5
Avg merge
2h 16m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ash-project/ash_lua

All issues in ash-project/ash_lua

Similar issues

More Elixir issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.