pub enum AppPathError {
ExecutableNotFound(String),
InvalidExecutablePath(String),
}
Expand description
Error type for AppPath operations.
This enum represents the possible failures that can occur when determining the executable location. These errors are rare in practice and typically indicate fundamental system issues.
§When These Errors Occur
-
ExecutableNotFound
: Whenstd::env::current_exe()
fails- Very rare, but can happen in some embedded or heavily sandboxed environments
- May occur if the executable has been deleted while running
- Can happen in some containerized environments with unusual configurations
-
InvalidExecutablePath
: When the executable path is empty- Extremely rare, indicates a corrupted or broken system
- May occur with custom or non-standard program loaders
These errors represent system-level failures that are typically unrecoverable
for portable applications. Most applications should use the infallible API
(new()
, exe_dir()
) and handle these rare cases through environment
variables or fallback strategies.
§Examples
use app_path::{AppPath, AppPathError};
// Handle errors explicitly
match AppPath::try_new("config.toml") {
Ok(config) => {
println!("Config path: {}", config.path().display());
}
Err(AppPathError::ExecutableNotFound(msg)) => {
eprintln!("Cannot find executable: {}", msg);
// Fallback to alternative configuration
}
Err(AppPathError::InvalidExecutablePath(msg)) => {
eprintln!("Invalid executable path: {}", msg);
// Fallback to alternative configuration
}
}
Variants§
ExecutableNotFound(String)
Failed to determine the current executable path.
This error occurs when std::env::current_exe()
fails, which is rare
but can happen in some embedded or heavily sandboxed environments.
InvalidExecutablePath(String)
Executable path is empty or invalid.
This error occurs when the system returns an empty executable path, which is extremely rare and indicates a corrupted or broken system.
Trait Implementations§
Source§impl Clone for AppPathError
impl Clone for AppPathError
Source§fn clone(&self) -> AppPathError
fn clone(&self) -> AppPathError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more