use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("mpv: {0}")]
Mpv(#[from] rsmpv::Error),
#[error("a render context is already attached")]
AlreadyAttached,
#[error("render call does not match the attached render backend")]
RenderBackendMismatch,
#[error("no render context is attached")]
NotAttached,
}
pub type Result<T> = std::result::Result<T, Error>;
pub(crate) fn describe_code(code: i32) -> String {
rsmpv::Error::from_raw(code).to_string()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn describe_code_carries_mpv_text_and_code() {
let msg = describe_code(-17);
assert!(msg.contains("format"), "unexpected message: {msg}");
assert!(msg.contains("-17"), "unexpected message: {msg}");
assert!(describe_code(-99).contains("-99"));
}
}