use std::{ffi::OsString, path::PathBuf, sync::Mutex};
use peace_core::ProfileInvalidFmt;
use peace_resources::paths::WorkspaceDir;
#[cfg_attr(feature = "error_reporting", derive(miette::Diagnostic))]
#[derive(Debug, thiserror::Error)]
pub enum NativeError {
#[error("Failed to present data.")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::cli_output_present))
)]
CliOutputPresent(#[source] std::io::Error),
#[error("Failed to set current dir to workspace directory: `{}`", workspace_dir.display())]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::current_dir_set))
)]
CurrentDirSet {
workspace_dir: WorkspaceDir,
#[source]
error: std::io::Error,
},
#[error("Failed to create file for writing: `{path}`")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::file_create))
)]
FileCreate {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Failed to open file for reading: `{path}`")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::file_open))
)]
FileOpen {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Failed to read from file: `{path}`")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::file_read))
)]
FileRead {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Failed to write to file: `{path}`")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::file_write))
)]
FileWrite {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Failed to list entries in `PeaceAppDir`: {}", peace_app_dir.display())]
PeaceAppDirRead {
peace_app_dir: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Failed to read entry in `PeaceAppDir`: {}", peace_app_dir.display())]
PeaceAppDirEntryRead {
peace_app_dir: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Failed to read entry file type in `PeaceAppDir`: {}", path.display())]
PeaceAppDirEntryFileTypeRead {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error("Profile directory name is not a valid profile name: {}, path: {}", dir_name, path.display())]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::profile_dir_invalid_name))
)]
ProfileDirInvalidName {
dir_name: String,
path: PathBuf,
error: ProfileInvalidFmt<'static>,
},
#[error("Failed to write to stdout.")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::stdout_write))
)]
StdoutWrite(#[source] std::io::Error),
#[error("Storage synchronous thread failed to be joined.")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::storage_sync_thread_spawn))
)]
StorageSyncThreadSpawn(#[source] std::io::Error),
#[error("Storage synchronous thread failed to be joined.")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::storage_sync_thread_join))
)]
StorageSyncThreadJoin(Mutex<Box<dyn std::any::Any + Send + 'static>>),
#[error("Failed to read current directory to discover workspace directory.")]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::working_dir_read))
)]
WorkingDirRead(#[source] std::io::Error),
#[error("Failed to create workspace directory: `{path}`.", path = path.display())]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::workspace_dir_create))
)]
WorkspaceDirCreate {
path: PathBuf,
#[source]
error: std::io::Error,
},
#[error(
"Failed to determine workspace directory as could not find `{file_name}` \
in `{working_dir}` or any parent directories.",
file_name = file_name.to_string_lossy(),
working_dir = working_dir.display())]
#[cfg_attr(
feature = "error_reporting",
diagnostic(code(peace_rt_model_native::workspace_file_not_found))
)]
WorkspaceFileNotFound {
working_dir: PathBuf,
file_name: OsString,
},
}