unity_solution_generator/
error.rs1use std::fmt;
2use std::io;
3
4pub type Result<T> = std::result::Result<T, GeneratorError>;
5
6#[derive(Debug)]
7pub enum GeneratorError {
8 Io { path: String, source: io::Error },
9 Lockfile(LockfileError),
10 DuplicateAsmDefName(String),
11 Other(String),
12}
13
14#[derive(Debug)]
15pub enum LockfileError {
16 NoProjectVersion(String),
17 UnityNotFound(String),
18 InvalidLockfile(String),
19}
20
21impl fmt::Display for GeneratorError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 GeneratorError::Io { path, source } => write!(f, "{}: {}", source, path),
25 GeneratorError::Lockfile(e) => write!(f, "{}", e),
26 GeneratorError::DuplicateAsmDefName(n) => write!(f, "Duplicate asmdef name: '{}'", n),
27 GeneratorError::Other(msg) => write!(f, "{}", msg),
28 }
29 }
30}
31
32impl fmt::Display for LockfileError {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 match self {
35 LockfileError::NoProjectVersion(p) => {
36 write!(f, "Cannot find ProjectSettings/ProjectVersion.txt in: {}", p)
37 }
38 LockfileError::UnityNotFound(p) => write!(f, "Unity installation not found at: {}", p),
39 LockfileError::InvalidLockfile(r) => write!(f, "Invalid lockfile: {}", r),
40 }
41 }
42}
43
44impl std::error::Error for GeneratorError {}
45impl std::error::Error for LockfileError {}
46
47impl From<LockfileError> for GeneratorError {
48 fn from(e: LockfileError) -> Self {
49 GeneratorError::Lockfile(e)
50 }
51}
52
53pub fn io_err(path: impl Into<String>, source: io::Error) -> GeneratorError {
54 GeneratorError::Io {
55 path: path.into(),
56 source,
57 }
58}