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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::ffi::NulError;
use std::io;
use std::num::ParseIntError;
use thiserror::Error;
use zip::result::ZipError;
#[derive(Error, Debug)]
pub enum TchError {
#[error("conversion error: {0}")]
Convert(String),
#[error("invalid file format: {0}")]
FileFormat(String),
#[error("cannot find the tensor named {0} in {1}")]
TensorNameNotFound(String, String),
#[error(transparent)]
Io(#[from] io::Error),
#[error("tensor kind error: {0}")]
Kind(String),
#[error("no image found in {0}")]
MissingImage(String),
#[error(transparent)]
Nul(#[from] NulError),
#[error(transparent)]
ParseInt(#[from] ParseIntError),
#[error("invalid shape: {0}")]
Shape(String),
#[error("unknown kind: {0}")]
UnknownKind(libc::c_int),
#[error("Internal torch error: {0}")]
Torch(String),
#[error(transparent)]
Zip(#[from] ZipError),
}
impl TchError {
pub fn path_context(&self, path_name: &str) -> Self {
match self {
TchError::Torch(error) => TchError::Torch(format!("{}: {}", path_name, error)),
_ => unimplemented!(),
}
}
}