From d5bb762020122c4dd23fea91a19a1d22805a3898 Mon Sep 17 00:00:00 2001 From: ApsisRS contributors Date: Sat, 26 Sep 2026 23:40:43 +0800 Subject: [PATCH] orbit: mark the new error enums non exhaustive EphemerisSamplingError and ManeuverApplicationError were missing the attribute the other fifteen error kinds carry. Record the distinction between an error enum, which is marked so a new category does not break a caller, and a domain state enum, which is left exhaustive so the compiler points at every match that a new variant needs. --- crates/orbit/apsis-orbit/src/orbit.rs | 2 ++ docs/design/errors.md | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/crates/orbit/apsis-orbit/src/orbit.rs b/crates/orbit/apsis-orbit/src/orbit.rs index a118c00..083cd93 100644 --- a/crates/orbit/apsis-orbit/src/orbit.rs +++ b/crates/orbit/apsis-orbit/src/orbit.rs @@ -222,6 +222,7 @@ impl Orbit { /// A failure while sampling an orbit into an ephemeris. #[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] pub enum EphemerisSamplingError { /// The requested grid is not usable: the step is not positive or the /// range is empty or reversed. @@ -247,6 +248,7 @@ impl core::error::Error for EphemerisSamplingError {} /// A failure while applying a burn to an orbit. #[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] pub enum ManeuverApplicationError { /// The state before the burn could not be propagated. Propagation(PropagationError), diff --git a/docs/design/errors.md b/docs/design/errors.md index dd75eea..c2475f5 100644 --- a/docs/design/errors.md +++ b/docs/design/errors.md @@ -40,6 +40,14 @@ impl core::error::Error for FooError {} - **`ErrorKind` 标注 `#[non_exhaustive]`**,这样新增一个失败类别不会破坏 下游的匹配。当前 15 个 `ErrorKind` 全部标注。 +- **错误枚举本身也标注 `#[non_exhaustive]`**,包括同时携带数据的错误枚举 + (如 `apsis-orbit` 的 `EphemerisSamplingError`,其变体包裹下层错误)。 +- **非错误的状态枚举不标注。** 领域状态(`TaskState`、`LinkState`、 + `TimeScale`、`HandoverDecision`、`Pattern` 的选择等)在单仓库 + 工作区内以**可穷尽匹配为优点**:新增一个变体时,编译器会指出每一处需要 + 更新的 `match`。这与错误的取舍相反——错误类别多一个,调用方应能继续 + 走默认分支;状态多一个,调用方通常必须显式处理。判断标准:该 enum 的 + 变体是否会被调用方 `match` 后对某些分支走默认?会,则标;不会,则不标。 - **`kind` 可精确匹配,`detail` 供人阅读。** 调用方按 `kind` 写恢复逻辑, 把 `detail` 记入日志。`detail` 不参与匹配,因此其措辞可自由改动。 - **`Display` 输出 `kind`,有 `detail` 时追加 `": detail"`。** 这样日志行