Skip to content

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

Open

Description

@JonasThowsen

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions