peace_rt_model_core/error/
native_error.rs1use std::{ffi::OsString, path::PathBuf, sync::Mutex};
2
3use peace_profile_model::ProfileInvalidFmt;
4use peace_resource_rt::paths::WorkspaceDir;
5
6#[cfg_attr(feature = "error_reporting", derive(miette::Diagnostic))]
8#[derive(Debug, thiserror::Error)]
9pub enum NativeError {
10 #[error("Failed to present data.")]
12 #[cfg_attr(
13 feature = "error_reporting",
14 diagnostic(code(peace_rt_model_native::cli_output_present))
15 )]
16 CliOutputPresent(#[source] std::io::Error),
17
18 #[error("Failed to set current dir to workspace directory: `{}`", workspace_dir.display())]
19 #[cfg_attr(
20 feature = "error_reporting",
21 diagnostic(code(peace_rt_model_native::current_dir_set))
22 )]
23 CurrentDirSet {
24 workspace_dir: WorkspaceDir,
26 #[source]
28 error: std::io::Error,
29 },
30
31 #[error("Failed to create file for writing: `{path}`")]
33 #[cfg_attr(
34 feature = "error_reporting",
35 diagnostic(code(peace_rt_model_native::file_create))
36 )]
37 FileCreate {
38 path: PathBuf,
40 #[source]
42 error: std::io::Error,
43 },
44
45 #[error("Failed to open file for reading: `{path}`")]
47 #[cfg_attr(
48 feature = "error_reporting",
49 diagnostic(code(peace_rt_model_native::file_open))
50 )]
51 FileOpen {
52 path: PathBuf,
54 #[source]
56 error: std::io::Error,
57 },
58
59 #[error("Failed to read from file: `{path}`")]
61 #[cfg_attr(
62 feature = "error_reporting",
63 diagnostic(code(peace_rt_model_native::file_read))
64 )]
65 FileRead {
66 path: PathBuf,
68 #[source]
70 error: std::io::Error,
71 },
72
73 #[error("Failed to write to file: `{path}`")]
75 #[cfg_attr(
76 feature = "error_reporting",
77 diagnostic(code(peace_rt_model_native::file_write))
78 )]
79 FileWrite {
80 path: PathBuf,
82 #[source]
84 error: std::io::Error,
85 },
86
87 #[error("Failed to list entries in `PeaceAppDir`: {}", peace_app_dir.display())]
89 PeaceAppDirRead {
90 peace_app_dir: PathBuf,
92 #[source]
94 error: std::io::Error,
95 },
96
97 #[error("Failed to read entry in `PeaceAppDir`: {}", peace_app_dir.display())]
99 PeaceAppDirEntryRead {
100 peace_app_dir: PathBuf,
102 #[source]
104 error: std::io::Error,
105 },
106
107 #[error("Failed to read entry file type in `PeaceAppDir`: {}", path.display())]
109 PeaceAppDirEntryFileTypeRead {
110 path: PathBuf,
112 #[source]
114 error: std::io::Error,
115 },
116
117 #[error("Profile directory name is not a valid profile name: {}, path: {}", dir_name, path.display())]
119 #[cfg_attr(
120 feature = "error_reporting",
121 diagnostic(code(peace_rt_model_native::profile_dir_invalid_name))
122 )]
123 ProfileDirInvalidName {
124 dir_name: String,
126 path: PathBuf,
128 error: ProfileInvalidFmt<'static>,
130 },
131
132 #[error("Failed to write to stdout.")]
134 #[cfg_attr(
135 feature = "error_reporting",
136 diagnostic(code(peace_rt_model_native::stdout_write))
137 )]
138 StdoutWrite(#[source] std::io::Error),
139
140 #[error("Storage synchronous thread failed to be joined.")]
145 #[cfg_attr(
146 feature = "error_reporting",
147 diagnostic(code(peace_rt_model_native::storage_sync_thread_spawn))
148 )]
149 StorageSyncThreadSpawn(#[source] std::io::Error),
150
151 #[error("Storage synchronous thread failed to be joined.")]
162 #[cfg_attr(
163 feature = "error_reporting",
164 diagnostic(code(peace_rt_model_native::storage_sync_thread_join))
165 )]
166 StorageSyncThreadJoin(Mutex<Box<dyn std::any::Any + Send + 'static>>),
167
168 #[error("Failed to read current directory to discover workspace directory.")]
170 #[cfg_attr(
171 feature = "error_reporting",
172 diagnostic(code(peace_rt_model_native::working_dir_read))
173 )]
174 WorkingDirRead(#[source] std::io::Error),
175
176 #[error("Failed to create workspace directory: `{path}`.", path = path.display())]
178 #[cfg_attr(
179 feature = "error_reporting",
180 diagnostic(code(peace_rt_model_native::workspace_dir_create))
181 )]
182 WorkspaceDirCreate {
183 path: PathBuf,
185 #[source]
187 error: std::io::Error,
188 },
189
190 #[error(
192 "Failed to determine workspace directory as could not find `{file_name}` \
193 in `{working_dir}` or any parent directories.",
194 file_name = file_name.to_string_lossy(),
195 working_dir = working_dir.display())]
196 #[cfg_attr(
197 feature = "error_reporting",
198 diagnostic(code(peace_rt_model_native::workspace_file_not_found))
199 )]
200 WorkspaceFileNotFound {
201 working_dir: PathBuf,
203 file_name: OsString,
205 },
206}