1use std::{
2 io,
3 num::{ParseFloatError, ParseIntError},
4 path::PathBuf,
5};
6
7use thiserror::Error;
8
9pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Debug, Error)]
12pub enum Error {
13 #[error("Input file {path:?} does not exist")]
14 InputNotAFile { path: PathBuf },
15
16 #[error("Target file {path:?} does not exist")]
17 TargetNotAFile { path: PathBuf },
18
19 #[error("Required tool(s) not found in PATH: {}", .tools.join(", "))]
20 MissingRequiredTools { tools: Vec<&'static str> },
21
22 #[error("Required tool `{tool}` not found in PATH")]
23 ToolNotFound { tool: &'static str },
24
25 #[error("Failed to start `{tool}`: {source}")]
26 ToolSpawn {
27 tool: &'static str,
28 #[source]
29 source: io::Error,
30 },
31
32 #[error("`{tool}` failed with exit code {code:?}: {stderr}")]
33 ToolFailed {
34 tool: &'static str,
35 code: Option<i32>,
36 stderr: String,
37 },
38
39 #[error("Unexpected output from `{tool}`: {line}")]
40 UnexpectedOutput { tool: &'static str, line: String },
41
42 #[error("Failed to parse integer field `{field}` from `{tool}` output: `{value}`")]
43 ParseInt {
44 tool: &'static str,
45 field: String,
46 value: String,
47 #[source]
48 source: ParseIntError,
49 },
50
51 #[error("Failed to parse float field `{field}` from `{tool}` output: `{value}`")]
52 ParseFloat {
53 tool: &'static str,
54 field: String,
55 value: String,
56 #[source]
57 source: ParseFloatError,
58 },
59
60 #[error("Unsupported output format `{format}`")]
61 UnsupportedFormat { format: String },
62
63 #[error("Unsupported value for {kind}: `{value}`")]
64 UnsupportedValue { kind: &'static str, value: String },
65
66 #[error("Missing HDR mastering display coordinates for {format}")]
67 MissingHdrColorCoordinates { format: &'static str },
68
69 #[error("I/O error while accessing {path:?}: {source}")]
70 Io {
71 path: PathBuf,
72 #[source]
73 source: io::Error,
74 },
75}