Files
photocraft/crates/codecs/src/error.rs
T
Brandon ThomasandClaude Opus 5.5 f7eb6ea9e7 Format: adopt the craft-family rustfmt.toml and format the workspace
CI's `cargo fmt --all -- --check` has failed on every run because the
repo had no rustfmt config and was never formatted. Use the same settings
as EffectCraft/FilmCraft (max_width 160, use_small_heuristics Max), which
also keeps the churn small. Formatting only; no code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 11:31:17 -04:00

32 lines
1.1 KiB
Rust

use crate::format::Format;
/// Errors produced by this crate. Decoders never panic on malformed input;
/// they return [`CodecError::Malformed`] instead.
#[derive(Debug, thiserror::Error)]
pub enum CodecError {
#[error("unrecognized image format")]
UnknownFormat,
#[error("{format:?}: {reason}")]
Unsupported { format: Format, reason: String },
#[error("{format:?}: malformed data: {message}")]
Malformed { format: Format, message: String },
#[error("limit exceeded: {0}")]
LimitExceeded(String),
#[error("{format:?}: encode failed: {message}")]
Encode { format: Format, message: String },
#[error("invalid image: {0}")]
InvalidImage(String),
}
impl CodecError {
pub(crate) fn malformed(format: Format, e: impl std::fmt::Display) -> Self {
CodecError::Malformed { format, message: e.to_string() }
}
pub(crate) fn encode(format: Format, e: impl std::fmt::Display) -> Self {
CodecError::Encode { format, message: e.to_string() }
}
pub(crate) fn unsupported(format: Format, reason: impl Into<String>) -> Self {
CodecError::Unsupported { format, reason: reason.into() }
}
}