#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub mod artifact;
pub mod builder;
pub(crate) mod canon;
pub mod content;
pub mod honesty;
pub mod model;
pub mod restamp;
pub mod status;
pub mod transform;
pub mod version;
pub use artifact::{Decoded, digest_of, from_bytes, from_file, read_from, to_bytes};
pub use builder::{AtomDraft, IrBuilder};
pub use content::{BlobId, ContentStore, Storage};
pub use honesty::{FidelityReport, summary};
pub use model::{
Annotation, AtomId, ChangeAtom, ChangedPart, Content, CopyRecord, DropRecord, Extra, Flag,
FlagKind, Identity, ImportProvenance, Ir, LossBoundary, LossClass, MetadataClaims, PathOp,
RefKind, RefRecord, Signature, SourceIdentity, SourceKind, Text, Time, TransformRecord,
};
pub use status::{Derivation, DerivationKind, EpistemicStatus};
pub use version::ContractVersion;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Decode(String),
DigestMismatch,
PreReleaseArtifact,
UnsupportedContract {
found: version::ContractVersion,
supported: version::ContractVersion,
},
UnknownCriticalField {
record: &'static str,
tag: u64,
},
NonCanonical(String),
Invariant(String),
Io(String),
ArtifactChanged(String),
ResourceLimit {
what: String,
ceiling: String,
},
}
impl Error {
pub(crate) fn io(e: std::io::Error) -> Self {
Self::Io(e.to_string())
}
pub(crate) fn io_msg(m: impl Into<String>) -> Self {
Self::Io(m.into())
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Decode(m) => write!(f, "malformed brygge-ir artifact: {m}"),
Self::DigestMismatch => {
write!(
f,
"brygge-ir integrity digest mismatch (tampered or truncated)"
)
}
Self::PreReleaseArtifact => write!(
f,
"this artifact predates brygge-ir contract 0.2.0 (a pre-release format); re-decode the \
source"
),
Self::UnsupportedContract { found, .. } => write!(
f,
"artifact contract {found} is not supported by this build (reads {})",
version::readable_summary()
),
Self::UnknownCriticalField { record, tag } => write!(
f,
"{record}: unrecognized critical field {tag}; this build cannot safely ignore it"
),
Self::NonCanonical(m) => write!(f, "brygge-ir artifact is not in canonical form: {m}"),
Self::Invariant(m) => write!(f, "brygge-ir invariant violated: {m}"),
Self::Io(m) => write!(f, "writing a brygge-ir artifact failed: {m}"),
Self::ArtifactChanged(m) => {
write!(f, "the artifact changed while it was being read: {m}")
}
Self::ResourceLimit { what, ceiling } => {
write!(f, "refused: {what} exceeds brygge's ceiling ({ceiling})")
}
}
}
}
impl std::error::Error for Error {}