Skip to main content

miden_mast_package/package/
error.rs

1use alloc::string::String;
2
3use miden_core::serde::DeserializationError;
4
5use super::section::SectionId;
6use crate::debug_info::InvalidOptionalIndexError;
7
8/// Errors raised while stripping package-owned debug information.
9#[derive(Debug, thiserror::Error)]
10pub enum PackageStripError {
11    #[error("failed to decode embedded kernel package while stripping debug info: {source}")]
12    DecodeEmbeddedKernel {
13        #[source]
14        source: DeserializationError,
15    },
16}
17
18/// Errors raised while decoding trusted package-owned debug information.
19#[derive(Debug, thiserror::Error)]
20pub enum PackageDebugInfoError {
21    #[error("package debug sections are present but are not trusted")]
22    /// Package debug sections are present on a package that does not trust them.
23    ///
24    /// Normal untrusted deserialization discards package-owned debug sections before returning a
25    /// package. This error protects callers from manually constructed packages, or future
26    /// deserialization paths, that retain debug sections without marking them trusted.
27    UntrustedSections,
28    #[error("package contains multiple '{id}' debug sections")]
29    DuplicateSection {
30        /// Duplicated section identifier.
31        id: SectionId,
32    },
33    #[error("failed to decode '{id}' debug section: {source}")]
34    DecodeSection {
35        /// Section identifier being decoded.
36        id: SectionId,
37        /// Underlying section deserialization error.
38        #[source]
39        source: DeserializationError,
40    },
41    #[error("'{id}' debug section has trailing bytes")]
42    TrailingBytes {
43        /// Section identifier with unused bytes after decoding.
44        id: SectionId,
45    },
46    #[error("invalid package debug info: {message}")]
47    InvalidReference { message: String },
48    #[error("invalid optional field discriminant for {context}: {err}")]
49    InvalidOptionField {
50        #[source]
51        err: InvalidOptionalIndexError,
52        context: String,
53    },
54}