webui_desktop_build/
error.rs1use std::path::PathBuf;
5
6#[derive(Debug, thiserror::Error)]
8pub enum GenerateError {
9 #[error("{code}: {context}: {message}\nhelp: {help}")]
11 Schema {
12 code: &'static str,
14 context: String,
16 message: String,
18 help: String,
20 },
21 #[error("ipc-tool: {tool}: {message}\nhelp: {help}")]
23 Tool {
24 tool: String,
26 message: String,
28 help: String,
30 },
31 #[error("ipc-io: {path}: {source}\nhelp: check the path and filesystem permissions")]
33 Io {
34 path: PathBuf,
36 #[source]
38 source: std::io::Error,
39 },
40 #[error("ipc-drift: generated artifacts differ: {paths:?}\nhelp: regenerate and commit all outputs together")]
42 Drift {
43 paths: Vec<PathBuf>,
45 },
46}
47
48impl GenerateError {
49 #[must_use]
51 pub fn code(&self) -> &'static str {
52 match self {
53 Self::Schema { code, .. } => code,
54 Self::Tool { .. } => "ipc-tool",
55 Self::Io { .. } => "ipc-io",
56 Self::Drift { .. } => "ipc-drift",
57 }
58 }
59}
60
61#[cold]
62pub(crate) fn schema(
63 code: &'static str,
64 context: impl Into<String>,
65 message: impl Into<String>,
66 help: impl Into<String>,
67) -> GenerateError {
68 GenerateError::Schema {
69 code,
70 context: context.into(),
71 message: message.into(),
72 help: help.into(),
73 }
74}
75
76pub(crate) fn io(path: &std::path::Path, source: std::io::Error) -> GenerateError {
77 GenerateError::Io {
78 path: path.into(),
79 source,
80 }
81}