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

未关闭 适合新手
#24 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
elixir

调研方向

从 lib/ash_lua/runtime.ex 中的 AshLua.Runtime.unwrap_bulk_result/3 和 lib/ash_lua/encoder.ex 中的 AshLua.Encoder.error_class/1 开始,然后追踪 get 如何编码同一个 NotFound 错误。以一致的方式转换或分类 bulk 错误,使 update 和 destroy 中缺失的 ID 像 get 一样报告类 "invalid";验证这三个操作都返回相同的类。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Elixir
星标
15
派生
5
平均合并
2 小时 16 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ash-project/ash_lua 的其他 Issue

查看 ash-project/ash_lua 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。