From 6dc567a4aedff15cf82a82601089cb0b87da4e26 Mon Sep 17 00:00:00 2001 From: Lahfir Date: Thu, 19 Feb 2026 11:49:17 -0800 Subject: [PATCH] fix: align error codes with spec (APP_NOT_FOUND, PERM_DENIED) and add -i shorthand --- README.md | 2 +- crates/core/src/error.rs | 10 +++++----- crates/core/src/snapshot.rs | 2 +- crates/macos/src/app_ops.rs | 2 +- src/cli.rs | 2 +- src/main.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0effc6b..5c4fe9e 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index 4d57f21..73eb49e 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -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", ) diff --git a/crates/core/src/snapshot.rs b/crates/core/src/snapshot.rs index af37a80..48a9993 100644 --- a/crates/core/src/snapshot.rs +++ b/crates/core/src/snapshot.rs @@ -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}'"), )) })? diff --git a/crates/macos/src/app_ops.rs b/crates/macos/src/app_ops.rs index 6ee3713..691bf59 100644 --- a/crates/macos/src/app_ops.rs +++ b/crates/macos/src/app_ops.rs @@ -62,7 +62,7 @@ pub fn launch_app_impl(id: &str, wait: bool) -> Result } } 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( diff --git a/src/cli.rs b/src/cli.rs index 7b4d392..d15c64f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, diff --git a/src/main.rs b/src/main.rs index 8f93f36..4b3f4af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 }