vapoursynth/vsscript/
errors.rs1use std::ffi::{CString, NulError};
2use std::{fmt, io};
3
4use thiserror::Error;
5
6#[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 #[error("Failed to create VSScript environment")]
28 ScriptCreationFailed,
29}
30
31impl From<NulError> for Error {
32 #[inline]
33 fn from(x: NulError) -> Self {
34 Error::CStringConversion(x)
35 }
36}
37
38impl From<VSScriptError> for Error {
39 #[inline]
40 fn from(x: VSScriptError) -> Self {
41 Error::VSScript(x)
42 }
43}
44
45pub(crate) type Result<T> = std::result::Result<T, Error>;
46
47#[derive(Error, Debug)]
49pub struct VSScriptError(CString);
50
51impl fmt::Display for VSScriptError {
52 #[inline]
53 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54 write!(f, "{}", self.0.to_string_lossy())
55 }
56}
57
58impl VSScriptError {
59 #[inline]
61 pub(crate) fn new(message: CString) -> Self {
62 VSScriptError(message)
63 }
64}