Skip to content

feat(xvm): tell the user why an install or removal was refused - #393

Merged
Sunrisepeak merged 1 commit into
release/0.4.70from
fix/xvm-user-facing-errors
Jul 26, 2026
Merged

Sunrisepeak merged 1 commit into
release/0.4.70from
fix/xvm-user-facing-errors

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

P0.4 of the 0.4.70 release train。

Problem

#384 让校验层 fail-closed,但失败只走 log::warn + return false。默认日志级别下用户只看到 install failed,看不到原因,也没有出口。

这在两个意义上是新问题:

  1. 有若干拒绝场景(OwnershipConflict、HeaderAmbiguous)在 origin/main 上是静默覆盖成功的。用户的第一感受会是"升级之后我原来能装的包装不上了",而不是"我的包有问题"。
  2. fail-closed 的价值主张只有在用户知道该怎么办时才成立。

Change

新增 xvm::XvmUserError —— 稳定 code、所属 release、出错的 target 与 JSON Pointer、以及一条指明动作的 hint。

[error] exact registration is owned by 'pkgindex:[email protected]'
          code:     xvm-ownership-conflict
          provider: pkgindex:[email protected]
          at:       [email protected]
          field:    /nodes/2
          hint:     another package already owns this exact name and version;
                    uninstall that package first, or install this one at a
                    different version
          nothing was changed

三个错误枚举(RegistrationErrorKind 17 + RemovalErrorKind 8 + BindingErrorKind 15 = 40 个)全部建立映射。

穷尽性双保险:switch 不带 default(新增枚举值编译期告警)+ 单测逐个列举全部 40 个值,对任何未分类、无 hint、或 code 重复的一律失败。

nothing was changed 是断言,不是修辞

三处接线全部传 nothingChanged=true,且逐处核对过而非假设:

  • 选择阶段(snapshot_xpkg_removal_context)在任何变更之前运行
  • apply_xpkg_xvm_metadata_batch 在 candidateDb/Workspace/Installed 副本上工作,只在成功时 swap 回去 —— 所有失败路径都在 swap 之前 return

测试 NothingWasChangedIsOnlyClaimedWhenAsked 保证这行字不会在没人担保时出现。

Tests

测试 覆盖
EveryRegistrationKindHasACodeAndHint 17 个枚举值
EveryRemovalKindHasACodeAndHint 8 个
EveryBindingKindHasACodeAndHint 15 个
RenderCarriesEveryFieldTheUserNeeds 渲染含 what/code/provider/at/field/hint
NothingWasChangedIsOnlyClaimedWhenAsked 不主动声称未改动
PeerOfAnAsymmetricEdgeIsShown 非对称边必须同时给出对端,否则只说了一半

Verification

mcpp build   →  Finished release [optimized] in 44.76s
mcpp test    →  test result ok. 11 passed; 0 failed
XvmUserError →  6 passed

CI 状态为已知上游拉取签名(见 #386),依计划 §3.1.1 合入集成分支。

The validation layers fail closed, which is only worth doing if the
person on the other side is told what happened. They were not: a
rejected batch went to log::warn and the command returned false, so at
the default log level the user saw 'install failed' and nothing else.

That reads as xlings breaking rather than as the package being
malformed, and it leaves no way out. It is also new -- several of these
refusals are cases that used to succeed by silently overwriting.

Add xvm::XvmUserError with a stable code, the owning release, the
offending target and JSON Pointer, and a hint that names an action.
Every kind of all three error enums maps to one; the mapping is a switch
with no default, so a new enumerator warns at compile time, and a test
enumerates all forty of them and fails on any that is unclassified,
hintless, or shares a code with another.

Wire it into the three installer paths that previously warned and
returned false. Each passes nothingChanged=true, which is checked rather
than assumed: selection runs before any mutation, and the metadata batch
works on copies it swaps in only on success, so every failure path
returns with the stored state untouched.

    [error] exact registration is owned by 'pkgindex:[email protected]'
              code:     xvm-ownership-conflict
              provider: pkgindex:[email protected]
              at:       [email protected]
              field:    /nodes/2
              hint:     another package already owns this exact name and
                        version; uninstall that package first, or install
                        this one at a different version
              nothing was changed
@Sunrisepeak
Sunrisepeak merged commit 553a8cc into release/0.4.70 Jul 26, 2026
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant