grok-build-upstream-mirror/crates/codegen/xai-grok-workspace/src/error.rs

103 lines
4.6 KiB
Rust
Raw Normal View History

//! Workspace error types.
use crate::capability::CapabilityMode;
/// Errors surfaced by the workspace public API.
///
/// `#[non_exhaustive]` so adding new variants is a non-breaking change.
/// Tests should match on variants rather than scrape the `Display` text.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum WorkspaceError {
#[error("parent session not found: {0}")]
ParentSessionNotFound(String),
#[error("session not found: {0}")]
SessionNotFound(String),
#[error("session already exists: {0}")]
SessionAlreadyExists(String),
#[error("agent_id must be non-empty")]
EmptyAgentId,
#[error("the main session cannot be dropped")]
CannotDropMainSession,
#[error("toolset finalization failed: {0}")]
Finalize(String),
#[error("capability widening rejected: child {child:?} is not a subset of parent {parent:?}")]
CapabilityWidening {
parent: CapabilityMode,
child: CapabilityMode,
},
#[error("session {caller:?} is not authorised to operate on session {target:?}")]
Unauthorized { caller: String, target: String },
/// A toolset mutation was rejected because the target session has an
/// active turn. Retryable at the turn boundary (`after_turn`).
#[error("turn active for session {0}; retry the tool-config update at the turn boundary")]
TurnActive(String),
#[error("maximum fork depth exceeded for parent session {parent:?}")]
MaxDepthExceeded { parent: String },
#[error("internal task failure: {0}")]
JoinError(String),
#[error("invalid hunk action: {0}")]
InvalidHunkAction(String),
#[error("hunk action failed: {0}")]
HunkActionFailed(String),
/// An error from the server connection or tool server.
#[error("hub error: {0}")]
HubError(String),
#[error("unknown workspace method: {0}")]
UnknownMethod(String),
#[error("workspace archive export failed: {0}")]
ExportArchiveLimitExceeded(String),
#[error("github export error: {message}")]
ExportGithub {
kind: xai_grok_workspace_types::rpc::export_github::ExportGithubError,
message: String,
},
/// The workspace is draining/shutting down and is no longer accepting new
/// sessions. Surfaced when a `bind`/create races a terminal drain so the
/// shared upload queue is never torn down out from under a fresh session.
#[error("workspace is shutting down; not accepting new sessions")]
ShuttingDown,
/// The session's toolset is externally owned — installed by a local
/// (shell) bind, its `Terminal` resource is not the session-owned
/// backend — so an RPC-driven toolset mutation is refused instead of
/// silently skipped. Hard error: retrying cannot succeed while the
/// local bind holds the toolset.
#[error("toolset externally owned (local bind), mutation refused: {0}")]
ToolsetExternallyOwned(String),
}
Synced from monorepo Changes: - Non-blocking coding-data sharing upsell banner - Consolidate remediation in Doctor - Auto mode defers fail-closed gate asks to the classifier - Coalesce marketplace list fetches - Allow removing a marketplace source by name - Contain hung git marketplace sources (timeouts, non-blocking refresh, unbrick modal) - Label failed workspace RPCs with error_kind - Drop redundant explicit tonic/prost deps from xai-grok-shell - Report real exit codes for completed background shells - Narrow the date-rollover reminder to date-bearing templates - Wire toolOverrides through the session and agent - Security: Bash(git:*) allowlist matches whole command chain by prefix - Split prompt-trigger telemetry and record classifier provenance - Raise connectors-manager timeout to 60s - Auto classifier honors recorded approvals for repeat actions - Apply doctor fixes in the TUI - Auto-mode classifier timeouts prompt instead of silently denying - Scope subagent completion drains to the owning session - Add the toolOverrides wire types - Set client_identifier=grok-agent-sdk - Accept both spellings of the workspace-teleport kill switch - Persist one-shot occurrence journal - Stop turns that poll the exact same tool call 16x in a row - Copy compaction checkpoint files when forking sessions - Auto-focus permission prompt from scrollback - Esc cancels the running turn in non-vim and minimal modes - List Ctrl+Z undo and redo in keyboard shortcuts - Out-of-process macOS mic capture - Show active auth mode on session-info - Install the npm binary under $GROK_HOME - Remove hover/click dead zones between dashboard items - Route startup warnings to doctor - Document [feedback.user] author identity config - Extend bang command timeout - Close combine-queued edit-hold race - Integrate relocation recovery - Expose privacy notice rollout flag - Break harness discovery ref cycle so connections can idle-evict - Shift/Alt+Enter inserts newline when editing a queued prompt - Gate project Claude permissions on folder trust - Echo response.create.event_id on response.created - Toast when session creation fails from disk full - Add shared test process lifecycle - Enable dynamic workflows by default - Add relocation transaction state machine - Add shared test sandbox - Surface auth failures on model-switch compact - Persist durable scheduler expiry - Confirm before removing extensions-modal items - Re-run compact and prompt after login when compact hit expired auth - Recap sends hosted tools under backend search
2026-07-22 19:18:53 +01:00
impl WorkspaceError {
/// Low-cardinality `error_kind` metric label: the variant name in
/// snake_case; `DeployError` reports its per-kind `wire_code()`.
pub fn metric_kind(&self) -> &'static str {
match self {
Self::ParentSessionNotFound(_) => "parent_session_not_found",
Self::SessionNotFound(_) => "session_not_found",
Self::SessionAlreadyExists(_) => "session_already_exists",
Self::EmptyAgentId => "empty_agent_id",
Self::CannotDropMainSession => "cannot_drop_main_session",
Self::Finalize(_) => "finalize",
Self::CapabilityWidening { .. } => "capability_widening",
Self::Unauthorized { .. } => "unauthorized",
Self::TurnActive(_) => "turn_active",
Self::MaxDepthExceeded { .. } => "max_depth_exceeded",
Self::JoinError(_) => "join_error",
Self::InvalidHunkAction(_) => "invalid_hunk_action",
Self::HunkActionFailed(_) => "hunk_action_failed",
Self::HubError(_) => "hub_error",
Self::UnknownMethod(_) => "unknown_method",
Self::ExportArchiveLimitExceeded(_) => "export_archive_limit_exceeded",
Self::ExportGithub { kind, .. } => kind.wire_code(),
Synced from monorepo Changes: - Non-blocking coding-data sharing upsell banner - Consolidate remediation in Doctor - Auto mode defers fail-closed gate asks to the classifier - Coalesce marketplace list fetches - Allow removing a marketplace source by name - Contain hung git marketplace sources (timeouts, non-blocking refresh, unbrick modal) - Label failed workspace RPCs with error_kind - Drop redundant explicit tonic/prost deps from xai-grok-shell - Report real exit codes for completed background shells - Narrow the date-rollover reminder to date-bearing templates - Wire toolOverrides through the session and agent - Security: Bash(git:*) allowlist matches whole command chain by prefix - Split prompt-trigger telemetry and record classifier provenance - Raise connectors-manager timeout to 60s - Auto classifier honors recorded approvals for repeat actions - Apply doctor fixes in the TUI - Auto-mode classifier timeouts prompt instead of silently denying - Scope subagent completion drains to the owning session - Add the toolOverrides wire types - Set client_identifier=grok-agent-sdk - Accept both spellings of the workspace-teleport kill switch - Persist one-shot occurrence journal - Stop turns that poll the exact same tool call 16x in a row - Copy compaction checkpoint files when forking sessions - Auto-focus permission prompt from scrollback - Esc cancels the running turn in non-vim and minimal modes - List Ctrl+Z undo and redo in keyboard shortcuts - Out-of-process macOS mic capture - Show active auth mode on session-info - Install the npm binary under $GROK_HOME - Remove hover/click dead zones between dashboard items - Route startup warnings to doctor - Document [feedback.user] author identity config - Extend bang command timeout - Close combine-queued edit-hold race - Integrate relocation recovery - Expose privacy notice rollout flag - Break harness discovery ref cycle so connections can idle-evict - Shift/Alt+Enter inserts newline when editing a queued prompt - Gate project Claude permissions on folder trust - Echo response.create.event_id on response.created - Toast when session creation fails from disk full - Add shared test process lifecycle - Enable dynamic workflows by default - Add relocation transaction state machine - Add shared test sandbox - Surface auth failures on model-switch compact - Persist durable scheduler expiry - Confirm before removing extensions-modal items - Re-run compact and prompt after login when compact hit expired auth - Recap sends hosted tools under backend search
2026-07-22 19:18:53 +01:00
Self::ShuttingDown => "shutting_down",
Self::ToolsetExternallyOwned(_) => "toolset_externally_owned",
}
}
}
/// Convenience alias for the workspace's primary `Result` type.
pub type WorkspaceResult<T> = Result<T, WorkspaceError>;
Synced from monorepo Changes: - Non-blocking coding-data sharing upsell banner - Consolidate remediation in Doctor - Auto mode defers fail-closed gate asks to the classifier - Coalesce marketplace list fetches - Allow removing a marketplace source by name - Contain hung git marketplace sources (timeouts, non-blocking refresh, unbrick modal) - Label failed workspace RPCs with error_kind - Drop redundant explicit tonic/prost deps from xai-grok-shell - Report real exit codes for completed background shells - Narrow the date-rollover reminder to date-bearing templates - Wire toolOverrides through the session and agent - Security: Bash(git:*) allowlist matches whole command chain by prefix - Split prompt-trigger telemetry and record classifier provenance - Raise connectors-manager timeout to 60s - Auto classifier honors recorded approvals for repeat actions - Apply doctor fixes in the TUI - Auto-mode classifier timeouts prompt instead of silently denying - Scope subagent completion drains to the owning session - Add the toolOverrides wire types - Set client_identifier=grok-agent-sdk - Accept both spellings of the workspace-teleport kill switch - Persist one-shot occurrence journal - Stop turns that poll the exact same tool call 16x in a row - Copy compaction checkpoint files when forking sessions - Auto-focus permission prompt from scrollback - Esc cancels the running turn in non-vim and minimal modes - List Ctrl+Z undo and redo in keyboard shortcuts - Out-of-process macOS mic capture - Show active auth mode on session-info - Install the npm binary under $GROK_HOME - Remove hover/click dead zones between dashboard items - Route startup warnings to doctor - Document [feedback.user] author identity config - Extend bang command timeout - Close combine-queued edit-hold race - Integrate relocation recovery - Expose privacy notice rollout flag - Break harness discovery ref cycle so connections can idle-evict - Shift/Alt+Enter inserts newline when editing a queued prompt - Gate project Claude permissions on folder trust - Echo response.create.event_id on response.created - Toast when session creation fails from disk full - Add shared test process lifecycle - Enable dynamic workflows by default - Add relocation transaction state machine - Add shared test sandbox - Surface auth failures on model-switch compact - Persist durable scheduler expiry - Confirm before removing extensions-modal items - Re-run compact and prompt after login when compact hit expired auth - Recap sends hosted tools under backend search
2026-07-22 19:18:53 +01:00
#[cfg(test)]
mod tests {
use super::WorkspaceError;
#[test]
fn metric_kind_is_message_free() {
let err = WorkspaceError::HubError("something wildly unique 12345".into());
assert_eq!(err.metric_kind(), "hub_error");
}
}