vapoursynth/vsscript/
errors.rs

1use std::ffi::{CString, NulError};
2use std::{fmt, io};
3
4use thiserror::Error;
5
6/// The error type for `vsscript` operations.
7#[derive(Error, Debug)]
8pub enum Error {
9    #[error("Couldn't convert to a CString")]
10    CStringConversion(#[source] NulError),
11    #[error("Couldn't open the file")]
12    FileOpen(#[source] io::Error),
13    #[error("Couldn't read the file")]
14    FileRead(#[source] io::Error),
15    #[error("Path isn't valid Unicode")]
16    PathInvalidUnicode,
17    #[error("An error occurred in VSScript")]
18    VSScript(#[source] VSScriptError),
19    #[error("There's no such variable")]
20    NoSuchVariable,
21    #[error("Couldn't get the core")]
22    NoCore,
23    #[error("There's no output on the requested index")]
24    NoOutput,
25    #[error("Couldn't get the VapourSynth API")]
26    NoAPI,
27}
28
29impl From<NulError> for Error {
30    #[inline]
31    fn from(x: NulError) -> Self {
32        Error::CStringConversion(x)
33    }
34}
35
36impl From<VSScriptError> for Error {
37    #[inline]
38    fn from(x: VSScriptError) -> Self {
39        Error::VSScript(x)
40    }
41}
42
43pub(crate) type Result<T> = std::result::Result<T, Error>;
44
45/// A container for a VSScript error.
46#[derive(Error, Debug)]
47pub struct VSScriptError(CString);
48
49impl fmt::Display for VSScriptError {
50    #[inline]
51    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52        write!(f, "{}", self.0.to_string_lossy())
53    }
54}
55
56impl VSScriptError {
57    /// Creates a new `VSScriptError` with the given error message.
58    #[inline]
59    pub(crate) fn new(message: CString) -> Self {
60        VSScriptError(message)
61    }
62}