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.
This commit is contained in:
ApsisRS contributors 2026-09-26 23:40:43 +08:00
parent 66d3cd3515
commit d5bb762020
2 changed files with 10 additions and 0 deletions

View File

@ -222,6 +222,7 @@ impl Orbit {
/// A failure while sampling an orbit into an ephemeris. /// A failure while sampling an orbit into an ephemeris.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum EphemerisSamplingError { pub enum EphemerisSamplingError {
/// The requested grid is not usable: the step is not positive or the /// The requested grid is not usable: the step is not positive or the
/// range is empty or reversed. /// range is empty or reversed.
@ -247,6 +248,7 @@ impl core::error::Error for EphemerisSamplingError {}
/// A failure while applying a burn to an orbit. /// A failure while applying a burn to an orbit.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ManeuverApplicationError { pub enum ManeuverApplicationError {
/// The state before the burn could not be propagated. /// The state before the burn could not be propagated.
Propagation(PropagationError), Propagation(PropagationError),

View File

@ -40,6 +40,14 @@ impl core::error::Error for FooError {}
- **`ErrorKind` 标注 `#[non_exhaustive]`**,这样新增一个失败类别不会破坏 - **`ErrorKind` 标注 `#[non_exhaustive]`**,这样新增一个失败类别不会破坏
下游的匹配。当前 15 个 `ErrorKind` 全部标注。 下游的匹配。当前 15 个 `ErrorKind` 全部标注。
- **错误枚举本身也标注 `#[non_exhaustive]`**,包括同时携带数据的错误枚举
(如 `apsis-orbit` 的 `EphemerisSamplingError`,其变体包裹下层错误)。
- **非错误的状态枚举不标注。** 领域状态(`TaskState`、`LinkState`、
`TimeScale`、`HandoverDecision`、`Pattern` 的选择等)在单仓库
工作区内以**可穷尽匹配为优点**:新增一个变体时,编译器会指出每一处需要
更新的 `match`。这与错误的取舍相反——错误类别多一个,调用方应能继续
走默认分支;状态多一个,调用方通常必须显式处理。判断标准:该 enum 的
变体是否会被调用方 `match` 后对某些分支走默认?会,则标;不会,则不标。
- **`kind` 可精确匹配,`detail` 供人阅读。** 调用方按 `kind` 写恢复逻辑, - **`kind` 可精确匹配,`detail` 供人阅读。** 调用方按 `kind` 写恢复逻辑,
把 `detail` 记入日志。`detail` 不参与匹配,因此其措辞可自由改动。 把 `detail` 记入日志。`detail` 不参与匹配,因此其措辞可自由改动。
- **`Display` 输出 `kind`,有 `detail` 时追加 `": detail"`。** 这样日志行 - **`Display` 输出 `kind`,有 `detail` 时追加 `": detail"`。** 这样日志行