Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 20 variants BadMagic { got: [u8; 8], }, UnsupportedVersion { found_major: u16, found_minor: u16, supported_major: u16, }, Truncated { context: &'static str, need: usize, got: usize, }, MalformedHeader { reason: &'static str, }, NoMatchingSlot, HeaderMacMismatch, ChunkAuthFailed { index: u64, }, UnknownCriticalTlv { tlv_type: u16, }, MissingTlv { tlv_type: u16, }, MalformedTlv { tlv_type: u16, reason: &'static str, }, ChunkOutOfRange { index: u64, total: u64, }, TooManySlots { got: usize, max: usize, }, InvalidChunkSize { got: u32, min: u32, max: u32, }, ShardCrcMismatch { index: u32, expected: u32, computed: u32, }, MissingShards { missing: Vec<u32>, total: u32, }, ShardUuidMismatch { index: u32, }, ContentHashMismatch, Compression { reason: String, }, KeyDerivation { reason: &'static str, }, Io(Error),
}
Expand description

omy 核心库的错误类型。

每个变体都携带定位问题所需的结构化字段,供上层渲染本地化消息。

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

BadMagic

文件头 magic 不匹配,不是 omy 文件。

Fields

§got: [u8; 8]

实际读到的前 8 字节。

§

UnsupportedVersion

主版本号高于本实现支持的上限,必须拒绝打开(规范 §9 步骤 2)。

Fields

§found_major: u16

文件声明的主版本。

§found_minor: u16

文件声明的次版本。

§supported_major: u16

本实现支持的最高主版本。

§

Truncated

输入数据长度不足,无法解析出完整结构。

Fields

§context: &'static str

正在解析的结构名,便于定位。

§need: usize

需要的字节数。

§got: usize

实际可用的字节数。

§

MalformedHeader

头部字段取值非法或自相矛盾。

Fields

§reason: &'static str

具体原因。

§

NoMatchingSlot

没有任何候选密钥能解开任何一个 key slot。

注意:这不代表文件损坏,也可能只是该文件不属于当前解锁的密码。 面向用户的文案必须同时表达这两种可能。

§

HeaderMacMismatch

头部 HMAC 校验失败:文件被篡改,或 FEK 不正确。

规范 §7 要求此时必须终止,不得继续读取载荷。

§

ChunkAuthFailed

载荷块的 AEAD 认证失败。

Fields

§index: u64

出错的块序号。

§

UnknownCriticalTlv

遇到未知且标记为 CRITICAL 的 TLV,按规范必须拒绝打开(§4.2)。

Fields

§tlv_type: u16

未知的 TLV 类型号。

§

MissingTlv

必需的 TLV 缺失。

Fields

§tlv_type: u16

缺失的 TLV 类型号。

§

MalformedTlv

TLV 内容解析失败。

Fields

§tlv_type: u16

出错的 TLV 类型号。

§reason: &'static str

具体原因。

§

ChunkOutOfRange

请求的块序号超出文件实际块数。

Fields

§index: u64

请求的块序号。

§total: u64

实际总块数。

§

TooManySlots

key slot 数量超过格式上限。

Fields

§got: usize

请求的数量。

§max: usize

格式允许的上限。

§

InvalidChunkSize

分块大小超出允许范围。

Fields

§got: u32

请求的分块大小。

§min: u32

下限。

§max: u32

上限。

§

ShardCrcMismatch

分片的 CRC-32 校验失败。

Fields

§index: u32

分片序号。

§expected: u32

头部记录的 CRC。

§computed: u32

实际算出的 CRC。

§

MissingShards

分片集合中缺少某些序号。

Fields

§missing: Vec<u32>

缺失的分片序号列表。

§total: u32

应有的总片数。

§

ShardUuidMismatch

分片的 file_uuid 与其它片不一致,属于不同文件。

Fields

§index: u32

不一致的分片序号。

§

ContentHashMismatch

解密后内容哈希与 TLV_CONTENT_HASH 记录不符。

§

Compression

压缩或解压失败。

Fields

§reason: String

具体原因。

§

KeyDerivation

密钥派生失败。

Fields

§reason: &'static str

具体原因。

§

Io(Error)

底层 IO 错误。

Implementations§

Source§

impl Error

Source

pub const fn exit_code(&self) -> ExitCode

映射到 CLI 退出码。

见 docs/research/09-cli-design.md §3.1。

Source

pub const fn code(&self) -> &'static str

稳定的机器可读错误码,供 --json 输出与前端 i18n 查表使用。

这些字符串是接口契约,脚本会匹配它们,因此不得随意更名。

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Forget for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.