#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum WeightsError {
#[error("model card canonical-json encode/decode failed: {0}")]
Encoding(String),
#[error("model card missing required field: {0}")]
MissingField(&'static str),
#[error("model card schema rejected: {0}")]
SchemaRejected(String),
#[error("model card expired at {expires_at}, now is {now}")]
Expired {
expires_at: chrono::DateTime<chrono::Utc>,
now: chrono::DateTime<chrono::Utc>,
},
#[error("model card cosign bundle rejected: {0}")]
BundleRejected(String),
#[error("weights_hash mismatch: card declares {expected}, runtime loaded {found}")]
CardMismatch {
expected: String,
found: String,
},
#[error("requested capability scope {scope:?} is not in card's allowed_capability_set")]
ScopeNotSubset {
scope: String,
},
#[error("requested tool {tool:?} is in card's banned_tools")]
ToolBanned {
tool: String,
},
}
impl WeightsError {
#[must_use]
pub fn urn(&self) -> &'static str {
match self {
Self::Encoding(_) => "urn:chio:error:weights:internal-encoding",
Self::MissingField(_) | Self::SchemaRejected(_) => {
"urn:chio:error:weights:schema-rejected"
}
Self::Expired { .. } => "urn:chio:error:weights:card-expired",
Self::BundleRejected(_) => "urn:chio:error:weights:bundle-rejected",
Self::CardMismatch { .. } => "urn:chio:error:weights:card-mismatch",
Self::ScopeNotSubset { .. } => "urn:chio:error:weights:scope-not-subset",
Self::ToolBanned { .. } => "urn:chio:error:weights:tool-banned",
}
}
}