use std::io;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ElevateError {
#[error("Win32 API '{operation}' failed: {source}")]
Win32 {
operation: &'static str,
#[source]
source: windows::core::Error,
},
#[error(
"Administrator privileges required: process must be run as Administrator (elevated) to acquire TrustedInstaller privileges"
)]
AdministratorRequired,
#[error(
"Privilege '{privilege}' is not held by the process token (run as Administrator to obtain it)"
)]
PrivilegeNotHeld {
privilege: &'static str,
},
#[error("Required system process '{0}' was not found in active session")]
ProcessNotFound(String),
#[error(
"Service '{name}' failed unexpectedly (win32 exit code: {exit_code}{})",
if *exit_code == 1066 {
format!(", service-specific exit code: {service_exit_code}")
} else {
String::new()
}
)]
ServiceFailed {
name: String,
exit_code: u32,
service_exit_code: u32,
},
#[error("Service '{name}' failed to reach running state within {seconds}s")]
ServiceTimeout {
name: String,
seconds: u64,
},
#[error(
"Session 0 is not supported with CallerSession target; use SessionTarget::AnyInteractive, Explicit, or ExecutionContext::Headless"
)]
SessionZeroNotSupported,
#[error("No interactive desktop session available on this machine")]
NoInteractiveSession,
#[error("I/O query failed: {0}")]
Io(#[from] io::Error),
#[error("Target executable path must be specified")]
MissingExePath,
#[error("Token information buffer is invalid or empty")]
InvalidTokenBuffer,
}