1use libseccomp::error::SeccompError;
2use nix::errno::Errno;
3use std::ffi::NulError;
4use std::io;
5use std::path::PathBuf;
6use std::string::FromUtf8Error;
7
8#[derive(Debug)]
9pub enum JudgeCoreError {
10 NixErrno(Errno),
11 SeccompError(SeccompError),
12 FFINulError(NulError),
13 IOError(io::Error),
14 SerdeJsonError(serde_json::Error),
15 AnyhowError(anyhow::Error),
16 FromUtf8Error(FromUtf8Error),
17}
18
19impl From<Errno> for JudgeCoreError {
20 fn from(error: Errno) -> JudgeCoreError {
21 JudgeCoreError::NixErrno(error)
22 }
23}
24
25impl From<SeccompError> for JudgeCoreError {
26 fn from(error: SeccompError) -> JudgeCoreError {
27 JudgeCoreError::SeccompError(error)
28 }
29}
30
31impl From<NulError> for JudgeCoreError {
32 fn from(error: NulError) -> JudgeCoreError {
33 JudgeCoreError::FFINulError(error)
34 }
35}
36
37impl From<io::Error> for JudgeCoreError {
38 fn from(error: io::Error) -> JudgeCoreError {
39 JudgeCoreError::IOError(error)
40 }
41}
42
43impl From<anyhow::Error> for JudgeCoreError {
44 fn from(error: anyhow::Error) -> JudgeCoreError {
45 JudgeCoreError::AnyhowError(error)
46 }
47}
48
49impl From<serde_json::Error> for JudgeCoreError {
50 fn from(error: serde_json::Error) -> JudgeCoreError {
51 JudgeCoreError::SerdeJsonError(error)
52 }
53}
54
55impl From<FromUtf8Error> for JudgeCoreError {
56 fn from(error: FromUtf8Error) -> JudgeCoreError {
57 JudgeCoreError::FromUtf8Error(error)
58 }
59}
60
61pub fn path_not_exist(path: &PathBuf) -> JudgeCoreError {
62 JudgeCoreError::AnyhowError(anyhow::anyhow!("Path not exist: {:?}", path))
63}