Skip to main content

elevate_ti/
error.rs

1//! Domain error types for `TrustedInstaller` elevation operations.
2
3use std::io;
4use thiserror::Error;
5
6/// The central error type for all privilege elevation and Windows security operations.
7#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum ElevateError {
10    /// A raw Win32 subsystem call failed.
11    #[error("Win32 API '{operation}' failed: {source}")]
12    Win32 {
13        /// Name of the Win32 function that failed.
14        operation: &'static str,
15        /// Underlying Windows error code and message.
16        #[source]
17        source: windows::core::Error,
18    },
19
20    /// A required Windows privilege could not be enabled.
21    #[error("Privilege '{0}' could not be assigned")]
22    PrivilegeNotAssigned(&'static str),
23
24    /// A required genuine Windows SYSTEM process was not found.
25    #[error("Required system process '{0}' was not found in active session")]
26    ProcessNotFound(String),
27
28    /// A Windows service failed to start or entered a failed state.
29    #[error("Service '{name}' failed unexpectedly")]
30    ServiceFailed {
31        /// Name of the target service.
32        name: String,
33    },
34
35    /// Waiting for a service to reach running state timed out.
36    #[error("Service '{name}' failed to reach running state within {seconds}s")]
37    ServiceTimeout {
38        /// Name of the target service.
39        name: String,
40        /// Elapsed time before giving up.
41        seconds: u64,
42    },
43
44    /// Caller is running in Session 0 (non-interactive service context).
45    #[error(
46        "Session 0 is not supported with CallerSession target; use SessionTarget::AnyInteractive, Explicit, or ExecutionContext::Headless"
47    )]
48    SessionZeroNotSupported,
49
50    /// No active interactive session with a logged-on user was found.
51    #[error("No interactive desktop session available on this machine")]
52    NoInteractiveSession,
53
54    /// An I/O error occurred during path resolution or execution.
55    #[error("I/O query failed: {0}")]
56    Io(#[from] io::Error),
57
58    /// Executable path was not provided prior to launch.
59    #[error("Target executable path must be specified")]
60    MissingExePath,
61
62    /// A query to token information returned corrupted or out-of-bounds data.
63    #[error("Token information buffer is invalid or empty")]
64    InvalidTokenBuffer,
65}