1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use thiserror::Error;

#[derive(Error, Debug)]
pub enum NvEncError {
    #[error("dynlink-cuda error`")]
    DynlinkCudaError(
        #[from]
        #[cfg_attr(feature = "backtrace", backtrace)]
        dynlink_cuda::CudaError,
    ),
    #[error("dynlink-nvidia-encode error")]
    DynlinkNvidiaEncodeError(
        #[from]
        #[cfg_attr(feature = "backtrace", backtrace)]
        dynlink_nvidia_encode::NvencError,
    ),
}

#[cfg(test)]
mod test {
    #[cfg(feature = "backtrace")]
    use std::{backtrace::Backtrace, error::Error};

    #[test]
    fn test_from_dynlink_cuda_error() {
        let orig = dynlink_cuda::CudaError::ErrCode {
            status: 2,
            #[cfg(feature = "backtrace")]
            backtrace: Backtrace::capture(),
        };
        #[allow(unused_variables)]
        let converted = crate::NvEncError::from(orig);
        #[cfg(feature = "backtrace")]
        assert!(converted.backtrace().is_some());
    }

    #[test]
    fn test_from_dynlink_nvidia_encode_error() {
        let orig = dynlink_nvidia_encode::NvencError::ErrCode {
            status: 2,
            message: "error",
            #[cfg(feature = "backtrace")]
            backtrace: Backtrace::capture(),
        };
        #[allow(unused_variables)]
        let converted = crate::NvEncError::from(orig);
        #[cfg(feature = "backtrace")]
        assert!(converted.backtrace().is_some());
    }
}