fix: align error codes with spec (APP_NOT_FOUND, PERM_DENIED) and add -i shorthand

This commit is contained in:
Lahfir 2026-02-19 11:49:17 -08:00
parent fb34600448
commit 6dc567a4ae
6 changed files with 10 additions and 10 deletions

View file

@ -143,7 +143,7 @@ Errors follow the same envelope with a structured error object:
|------|---------|
| `PERM_DENIED` | Accessibility permission not granted |
| `ELEMENT_NOT_FOUND` | No element matched the given ref or query |
| `APP_NOT_FOUND` | Target application is not running |
| `APP_NOT_FOUND` | Application is not running or has no open windows |
| `ACTION_FAILED` | The OS rejected the action |
| `ACTION_NOT_SUPPORTED` | Element does not support the requested action |
| `STALE_REF` | Ref is from a previous snapshot |

View file

@ -4,9 +4,9 @@ use thiserror::Error;
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ErrorCode {
PermissionDenied,
PermDenied,
ElementNotFound,
ApplicationNotFound,
AppNotFound,
ActionFailed,
ActionNotSupported,
StaleRef,
@ -20,9 +20,9 @@ pub enum ErrorCode {
impl ErrorCode {
pub fn as_str(&self) -> &'static str {
match self {
ErrorCode::PermissionDenied => "PERMISSION_DENIED",
ErrorCode::PermDenied => "PERM_DENIED",
ErrorCode::ElementNotFound => "ELEMENT_NOT_FOUND",
ErrorCode::ApplicationNotFound => "APPLICATION_NOT_FOUND",
ErrorCode::AppNotFound => "APP_NOT_FOUND",
ErrorCode::ActionFailed => "ACTION_FAILED",
ErrorCode::ActionNotSupported => "ACTION_NOT_SUPPORTED",
ErrorCode::StaleRef => "STALE_REF",
@ -99,7 +99,7 @@ impl AdapterError {
}
pub fn permission_denied() -> Self {
Self::new(ErrorCode::PermissionDenied, "Accessibility permission not granted")
Self::new(ErrorCode::PermDenied, "Accessibility permission not granted")
.with_suggestion(
"Open System Settings > Privacy & Security > Accessibility and add your terminal",
)

View file

@ -47,7 +47,7 @@ pub fn build(
})
.ok_or_else(|| {
AppError::Adapter(crate::error::AdapterError::new(
crate::error::ErrorCode::ApplicationNotFound,
crate::error::ErrorCode::AppNotFound,
format!("No window found for app '{app}'"),
))
})?

View file

@ -62,7 +62,7 @@ pub fn launch_app_impl(id: &str, wait: bool) -> Result<WindowInfo, AdapterError>
}
}
return Err(AdapterError::new(
agent_desktop_core::error::ErrorCode::ApplicationNotFound,
agent_desktop_core::error::ErrorCode::AppNotFound,
format!("App '{id}' launched but no window found within timeout"),
)
.with_suggestion(

View file

@ -103,7 +103,7 @@ pub struct SnapshotArgs {
pub max_depth: u8,
#[arg(long)]
pub include_bounds: bool,
#[arg(long)]
#[arg(long, short = 'i')]
pub interactive_only: bool,
#[arg(long)]
pub compact: bool,

View file

@ -72,7 +72,7 @@ fn main() {
"ok": false,
"command": cmd_name,
"error": {
"code": "PERMISSION_DENIED",
"code": "PERM_DENIED",
"message": "Accessibility permission not granted",
"suggestion": suggestion
}