Skip to main content

rff_core/
error.rs

1//! Unified error type for the whole workspace.
2
3use crate::media::CodecId;
4
5/// The workspace-wide result alias. Every fallible API returns this.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors produced anywhere in the pipeline.
9///
10/// The `Again` and `Eof` variants intentionally mirror FFmpeg's `EAGAIN` /
11/// `AVERROR_EOF` control-flow signals from the send/receive codec API: they are
12/// not "failures" so much as "ask again later" / "stream is finished".
13#[derive(Debug, thiserror::Error)]
14#[non_exhaustive]
15pub enum Error {
16    /// A code path that is scaffolded but not yet implemented. Carries a short
17    /// static label so logs point straight at the missing piece.
18    #[error("not yet implemented: {0}")]
19    Unimplemented(&'static str),
20
21    /// End of stream — a demuxer or decoder has no more data to give.
22    #[error("end of stream")]
23    Eof,
24
25    /// More input is required before output can be produced (codec drain/fill).
26    #[error("more input required")]
27    Again,
28
29    /// The input bytes were malformed for the expected format/codec.
30    #[error("invalid data: {0}")]
31    InvalidData(String),
32
33    /// A requested capability exists in concept but isn't supported here.
34    #[error("unsupported: {0}")]
35    Unsupported(String),
36
37    /// No registered decoder could handle this codec.
38    #[error("no decoder found for codec {0}")]
39    DecoderNotFound(CodecId),
40
41    /// No registered encoder could handle this codec.
42    #[error("no encoder found for codec {0}")]
43    EncoderNotFound(CodecId),
44
45    /// No registered muxer matched the requested container name/extension.
46    #[error("no muxer found for format `{0}`")]
47    MuxerNotFound(String),
48
49    /// No registered demuxer could probe/handle the input.
50    #[error("no demuxer found for input `{0}`")]
51    DemuxerNotFound(String),
52
53    /// A passed option was not recognised or had an invalid value.
54    #[error("invalid option: {0}")]
55    Option(String),
56
57    /// Underlying I/O failure.
58    #[error("i/o error: {0}")]
59    Io(#[from] std::io::Error),
60}
61
62impl Error {
63    /// Convenience constructor for `InvalidData` from anything string-like.
64    pub fn invalid(msg: impl Into<String>) -> Self {
65        Error::InvalidData(msg.into())
66    }
67
68    /// Convenience constructor for `Unsupported`.
69    pub fn unsupported(msg: impl Into<String>) -> Self {
70        Error::Unsupported(msg.into())
71    }
72}