1use std::fmt;
4use std::str::FromStr;
5
6use serde::{Deserialize, Deserializer, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct UnknownAtmErrorCode(pub String);
10
11impl fmt::Display for UnknownAtmErrorCode {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 write!(f, "unknown ATM error code: {}", self.0)
14 }
15}
16
17impl std::error::Error for UnknownAtmErrorCode {}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub enum AtmErrorCode {
21 ConfigHomeUnavailable,
22 AtmHomeUnresolved,
23 ConfigParseFailed,
24 ConfigRetiredHookMembersKey,
25 ConfigRetiredLegacyHookKeys,
26 ConfigTeamParseFailed,
27 ConfigTeamMissing,
28 IdentityUnavailable,
29 IdentityInvalid,
30 IdentityConflict,
31 MemberAlreadyExists,
32 MemberNotFound,
33 DaemonUnavailable,
34 RuntimeRootInvalid,
35 RuntimeBootstrapRefused,
36 SocketOverrideForbidden,
37 DaemonMayHaveExecuted,
38 DaemonLifecycleWedge,
39 DaemonLaunchGateRejected,
40 DaemonServingStateRejected,
41 DaemonStaleOwnerRecoveryFailed,
42 DaemonAutoStartFailed,
43 DaemonConnectionSaturated,
44 BlockingBridgeDeadlineBeforeStart,
45 BlockingBridgeDeadlineAfterStart,
46 RemoteDeliveryUnconfirmed,
47 PeerWireModeInvalid,
49 PeerWireModeSourceForbidden,
51 PeerWirePlaintextAuthenticationRequired,
53 PeerConfigValidationFailed,
54 CertificateOperationFailed,
55 PeerAuthenticationFailed,
57 TransportTimeout,
59 TransportProtocolFailed,
61 BindPreflightFailed,
62 ClientDaemonVersionIncompatible,
63 DaemonAdvisorySessionAlreadyRegistered,
64 DaemonAdvisorySessionNotRegistered,
65 DaemonAdvisorySessionCleanupFailed,
66 AddressParseFailed,
67 TeamUnavailable,
68 TeamInvalid,
69 TeamNotFound,
70 AgentNotFound,
71 MailboxReadFailed,
72 MailboxWriteFailed,
73 MailboxLockFailed,
74 MailboxLockReadOnlyFilesystem,
75 MailboxLockTimeout,
76 InternalError,
77 MessageValidationFailed,
78 TaskNotFound,
79 TaskAlreadyActive,
80 TaskAlreadyClosed,
81 TaskNotCounterparty,
82 TaskStaleCounterparty,
83 TaskMoveInvalid,
84 TaskMaxActiveReached,
85 SearchLocalOnly,
88 LocalHttpCapabilityInvalid,
89 LocalHttpEndpointSchemaUnsupported,
90 LocalHttpEndpointMissing,
91 LocalHttpEndpointNonLoopback,
92 LocalHttpRuntimeDirectoryMissing,
93 LocalHttpCapabilityRevoked,
94 MessageIdConflict,
95 SelfAddressedSendInvalid,
96 EmptyNudgeTemplateBody,
97 CallerContextRequestInvalid,
98 TemplateContentNotUtf8,
100 DecomposedTemplateIncludeForbidden,
102 TemplateLoadFailed,
103 TemplateHashApiFailed,
104 TemplateInspectionParseFailed,
106 TemplateRequiredVariableMissing,
107 TemplateVariableResolutionFailed,
108 TemplateRenderVerificationFailed,
109 TemplateIncludeUnresolved,
110 TemplateClassificationInvalid,
111 TemplateWorkflowInvalid,
112 TemplateWorkflowValueInvalid,
113 TemplateTagReserved,
114 WorkflowQueryInvalid,
116 WorkflowTelemetryConfigInvalid,
118 TelemetryExportConfigInvalid,
120 WorkflowTelemetryDropped,
122 SerializationFailed,
123 FilePolicyRejected,
124 FileReferenceRewriteFailed,
125 WaitTimeout,
126 AckInvalidState,
127 ClearInvalidState,
128 ObservabilityEmitFailed,
129 ObservabilityQueryFailed,
130 ObservabilityFollowFailed,
131 ObservabilityHealthFailed,
132 ObservabilityBootstrapFailed,
133 ObservabilityHealthOk,
134 RetainedDiagnosticsHealthOk,
135 WarningInvalidTeamMemberSkipped,
136 WarningMailboxRecordSkipped,
137 WarningMalformedAtmFieldIgnored,
138 WarningObservabilityHealthDegraded,
139 WarningRetainedDiagnosticsDegraded,
140 WarningSqliteHealthDegraded,
141 WarningOriginInboxEntrySkipped,
142 WarningMissingTeamConfigFallback,
143 WarningSendAlertStateDegraded,
144 WarningIdentityDrift,
145 WarningRosterDrift,
146 WarningHerdrUnnamedAgentTarget,
148 WarningBaselineMemberMissing,
149 WarningRestoreInProgress,
150 WarningStaleMailboxLock,
151 WarningHookSkipped,
152 WarningHookExecutionFailed,
153 RosterNoLead,
154 RosterMultipleLeads,
155 RosterReservedName,
156 TaskStalled,
157 MemberBlocked,
158 RosterMixedLocalBackend,
160 HerdrAgentNotVisible,
162 PostSendPaneMissing,
163 PostSendTmuxSendFailed,
164 PostSendHerdrPromptFailed,
165 HerdrPromptFailed,
166 HerdrUnavailable,
167 PostSendGraftUnavailable,
168 GraftReceiverAlreadyActive,
169 GraftReceiverNotOwner,
172 GraftReceiverNotRegistered,
174 PostSendAdvisoryDeliveryFailed,
175 TestFakeTransportInjectionFailed,
176 HelpTopicNotFound,
177 HookModuleInvalid,
179 CronExprInvalid,
181 CronTriggerDelayInvalid,
183 HookRefused,
185 HookExit,
187 HookTimeout,
189 HookMalformed,
191 StoreQueryFailed,
193 ToolSenderUnregistered,
195 ToolSenderReserved,
197 ToolSenderUnauthorized,
199 ToolKeyUnknown,
201 ToolKeyRevoked,
203 ToolNonceReplay,
205 ToolHostMismatch,
207 ToolGenerationConflict,
209 ToolSignatureInvalid,
211 ToolRequestExpired,
213 ToolCommitUncertain,
215}
216
217impl AtmErrorCode {
218 pub fn as_str(self) -> &'static str {
219 if let Some(value) = self.config_or_identity_str() {
220 return value;
221 }
222 if let Some(value) = self.daemon_or_address_str() {
223 return value;
224 }
225 if let Some(value) = self.mailbox_or_validation_str() {
226 return value;
227 }
228 if let Some(value) = self.observability_or_warning_str() {
229 return value;
230 }
231 self.post_send_or_misc_str()
232 }
233
234 fn config_or_identity_str(self) -> Option<&'static str> {
235 Some(match self {
236 Self::ConfigHomeUnavailable => "ATM_CONFIG_HOME_UNAVAILABLE",
237 Self::AtmHomeUnresolved => "ATM_HOME_UNRESOLVED",
238 Self::ConfigParseFailed => "ATM_CONFIG_PARSE_FAILED",
239 Self::ConfigRetiredHookMembersKey => "ATM_CONFIG_RETIRED_HOOK_MEMBERS_KEY",
240 Self::ConfigRetiredLegacyHookKeys => "ATM_CONFIG_RETIRED_LEGACY_HOOK_KEYS",
241 Self::ConfigTeamParseFailed => "ATM_CONFIG_TEAM_PARSE_FAILED",
242 Self::ConfigTeamMissing => "ATM_CONFIG_TEAM_MISSING",
243 Self::IdentityUnavailable => "ATM_IDENTITY_UNAVAILABLE",
244 Self::IdentityInvalid => "ATM_IDENTITY_INVALID",
245 Self::IdentityConflict => "ATM_IDENTITY_CONFLICT",
246 Self::MemberAlreadyExists => "ATM_MEMBER_ALREADY_EXISTS",
247 Self::MemberNotFound => "ATM_MEMBER_NOT_FOUND",
248 _ => return None,
249 })
250 }
251
252 fn daemon_or_address_str(self) -> Option<&'static str> {
253 Some(match self {
254 Self::DaemonUnavailable => "ATM_DAEMON_UNAVAILABLE",
255 Self::RuntimeRootInvalid => "ATM_RUNTIME_ROOT_INVALID",
256 Self::RuntimeBootstrapRefused => "ATM_RUNTIME_BOOTSTRAP_REFUSED",
257 Self::SocketOverrideForbidden => "ATM_SOCKET_OVERRIDE_FORBIDDEN",
258 Self::DaemonMayHaveExecuted => "ATM_DAEMON_MAY_HAVE_EXECUTED",
259 Self::DaemonLifecycleWedge => "ATM_DAEMON_LIFECYCLE_WEDGE",
260 Self::DaemonLaunchGateRejected => "ATM_DAEMON_LAUNCH_GATE_REJECTED",
261 Self::DaemonServingStateRejected => "ATM_DAEMON_SERVING_STATE_REJECTED",
262 Self::DaemonStaleOwnerRecoveryFailed => "ATM_DAEMON_STALE_OWNER_RECOVERY_FAILED",
263 Self::DaemonAutoStartFailed => "ATM_DAEMON_AUTO_START_FAILED",
264 Self::DaemonConnectionSaturated => "ATM_DAEMON_CONNECTION_SATURATED",
265 Self::BlockingBridgeDeadlineBeforeStart => "ATM_BLOCKING_BRIDGE_DEADLINE_BEFORE_START",
266 Self::BlockingBridgeDeadlineAfterStart => "ATM_BLOCKING_BRIDGE_DEADLINE_AFTER_START",
267 Self::RemoteDeliveryUnconfirmed => "REMOTE_DELIVERY_UNCONFIRMED",
268 Self::PeerWireModeInvalid => "ATM_PEER_WIRE_MODE_INVALID",
269 Self::PeerWireModeSourceForbidden => "ATM_PEER_WIRE_MODE_SOURCE_FORBIDDEN",
270 Self::PeerWirePlaintextAuthenticationRequired => {
271 "ATM_PEER_WIRE_PLAINTEXT_AUTHENTICATION_REQUIRED"
272 }
273 Self::PeerConfigValidationFailed => "ATM_PEER_CONFIG_VALIDATION_FAILED",
274 Self::CertificateOperationFailed => "ATM_CERTIFICATE_OPERATION_FAILED",
275 Self::PeerAuthenticationFailed => "ATM_PEER_AUTHENTICATION_FAILED",
276 Self::TransportTimeout => "ATM_TRANSPORT_TIMEOUT",
277 Self::TransportProtocolFailed => "ATM_TRANSPORT_PROTOCOL_FAILED",
278 Self::BindPreflightFailed => "ATM_BIND_PREFLIGHT_FAILED",
279 Self::ClientDaemonVersionIncompatible => "ATM_CLIENT_DAEMON_VERSION_INCOMPATIBLE",
280 Self::DaemonAdvisorySessionAlreadyRegistered => {
281 "ATM_DAEMON_ADVISORY_SESSION_ALREADY_REGISTERED"
282 }
283 Self::DaemonAdvisorySessionNotRegistered => {
284 "ATM_DAEMON_ADVISORY_SESSION_NOT_REGISTERED"
285 }
286 Self::DaemonAdvisorySessionCleanupFailed => {
287 "ATM_DAEMON_ADVISORY_SESSION_CLEANUP_FAILED"
288 }
289 Self::AddressParseFailed => "ATM_ADDRESS_PARSE_FAILED",
290 Self::TeamUnavailable => "ATM_TEAM_UNAVAILABLE",
291 Self::TeamInvalid => "ATM_TEAM_INVALID",
292 Self::TeamNotFound => "ATM_TEAM_NOT_FOUND",
293 Self::AgentNotFound => "ATM_AGENT_NOT_FOUND",
294 _ => return None,
295 })
296 }
297
298 fn mailbox_or_validation_str(self) -> Option<&'static str> {
299 Some(match self {
300 Self::MailboxReadFailed => "ATM_MAILBOX_READ_FAILED",
301 Self::MailboxWriteFailed => "ATM_MAILBOX_WRITE_FAILED",
302 Self::MailboxLockFailed => "ATM_MAILBOX_LOCK_FAILED",
303 Self::MailboxLockReadOnlyFilesystem => "ATM_MAILBOX_LOCK_READ_ONLY_FILESYSTEM",
304 Self::MailboxLockTimeout => "ATM_MAILBOX_LOCK_TIMEOUT",
305 Self::InternalError => "ATM_INTERNAL_ERROR",
306 Self::MessageValidationFailed => "ATM_MESSAGE_VALIDATION_FAILED",
307 Self::TaskNotFound => "ATM_TASK_NOT_FOUND",
308 Self::TaskAlreadyActive => "ATM_TASK_ALREADY_ACTIVE",
309 Self::TaskAlreadyClosed => "ATM_TASK_ALREADY_CLOSED",
310 Self::TaskNotCounterparty => "ATM_TASK_NOT_COUNTERPARTY",
311 Self::TaskStaleCounterparty => "ATM_TASK_STALE_COUNTERPARTY",
312 Self::TaskMoveInvalid => "ATM_TASK_MOVE_INVALID",
313 Self::TaskMaxActiveReached => "ATM_TASK_MAX_ACTIVE_REACHED",
314 Self::SearchLocalOnly => "ATM_SEARCH_LOCAL_ONLY",
315 Self::LocalHttpCapabilityInvalid => "ATM_LOCAL_HTTP_CAPABILITY_INVALID",
316 Self::LocalHttpEndpointSchemaUnsupported => {
317 "ATM_LOCAL_HTTP_ENDPOINT_SCHEMA_UNSUPPORTED"
318 }
319 Self::LocalHttpEndpointMissing => "ATM_LOCAL_HTTP_ENDPOINT_MISSING",
320 Self::LocalHttpEndpointNonLoopback => "ATM_LOCAL_HTTP_ENDPOINT_NON_LOOPBACK",
321 Self::LocalHttpRuntimeDirectoryMissing => "ATM_LOCAL_HTTP_RUNTIME_DIRECTORY_MISSING",
322 Self::LocalHttpCapabilityRevoked => "ATM_LOCAL_HTTP_CAPABILITY_REVOKED",
323 Self::MessageIdConflict => "ATM_MESSAGE_ID_CONFLICT",
324 Self::SelfAddressedSendInvalid => "ATM_SELF_ADDRESSED_SEND_INVALID",
325 Self::EmptyNudgeTemplateBody => "ATM_NUDGE_TEMPLATE_BODY_EMPTY",
326 Self::CallerContextRequestInvalid => "ATM_CALLER_CONTEXT_REQUEST_INVALID",
327 Self::TemplateContentNotUtf8 => "TEMPLATE_CONTENT_NOT_UTF8",
328 Self::DecomposedTemplateIncludeForbidden => "DECOMPOSED_TEMPLATE_INCLUDE_FORBIDDEN",
329 Self::TemplateLoadFailed => "TEMPLATE_LOAD_FAILED",
330 Self::TemplateHashApiFailed => "TEMPLATE_HASH_API_FAILED",
331 Self::TemplateInspectionParseFailed => "TEMPLATE_INSPECTION_PARSE_FAILED",
332 Self::TemplateRequiredVariableMissing => "TEMPLATE_REQUIRED_VARIABLE_MISSING",
333 Self::TemplateVariableResolutionFailed => "TEMPLATE_VARIABLE_RESOLUTION_FAILED",
334 Self::TemplateRenderVerificationFailed => "TEMPLATE_RENDER_VERIFICATION_FAILED",
335 Self::TemplateIncludeUnresolved => "TEMPLATE_INCLUDE_UNRESOLVED",
336 Self::TemplateClassificationInvalid => "TEMPLATE_CLASSIFICATION_INVALID",
337 Self::TemplateWorkflowInvalid => "TEMPLATE_WORKFLOW_INVALID",
338 Self::TemplateWorkflowValueInvalid => "TEMPLATE_WORKFLOW_VALUE_INVALID",
339 Self::TemplateTagReserved => "TEMPLATE_TAG_RESERVED",
340 Self::WorkflowQueryInvalid => "ATM_WORKFLOW_QUERY_INVALID",
341 Self::WorkflowTelemetryConfigInvalid => "ATM_WORKFLOW_TELEMETRY_CONFIG_INVALID",
342 Self::TelemetryExportConfigInvalid => "ATM_TELEMETRY_EXPORT_CONFIG_INVALID",
343 Self::WorkflowTelemetryDropped => "ATM_WORKFLOW_TELEMETRY_DROPPED",
344 Self::SerializationFailed => "ATM_SERIALIZATION_FAILED",
345 Self::FilePolicyRejected => "ATM_FILE_POLICY_REJECTED",
346 Self::FileReferenceRewriteFailed => "ATM_FILE_REFERENCE_REWRITE_FAILED",
347 Self::WaitTimeout => "ATM_WAIT_TIMEOUT",
348 Self::AckInvalidState => "ATM_ACK_INVALID_STATE",
349 Self::ClearInvalidState => "ATM_CLEAR_INVALID_STATE",
350 _ => return None,
351 })
352 }
353
354 fn observability_or_warning_str(self) -> Option<&'static str> {
355 Some(match self {
356 Self::ObservabilityEmitFailed => "ATM_OBSERVABILITY_EMIT_FAILED",
357 Self::ObservabilityQueryFailed => "ATM_OBSERVABILITY_QUERY_FAILED",
358 Self::ObservabilityFollowFailed => "ATM_OBSERVABILITY_FOLLOW_FAILED",
359 Self::ObservabilityHealthFailed => "ATM_OBSERVABILITY_HEALTH_FAILED",
360 Self::ObservabilityBootstrapFailed => "ATM_OBSERVABILITY_BOOTSTRAP_FAILED",
361 Self::ObservabilityHealthOk => "ATM_OBSERVABILITY_HEALTH_OK",
362 Self::RetainedDiagnosticsHealthOk => "ATM_RETAINED_DIAGNOSTICS_HEALTH_OK",
363 Self::WarningInvalidTeamMemberSkipped => "ATM_WARNING_INVALID_TEAM_MEMBER_SKIPPED",
364 Self::WarningMailboxRecordSkipped => "ATM_WARNING_MAILBOX_RECORD_SKIPPED",
365 Self::WarningMalformedAtmFieldIgnored => "ATM_WARNING_MALFORMED_ATM_FIELD_IGNORED",
366 Self::WarningObservabilityHealthDegraded => "ATM_WARNING_OBSERVABILITY_HEALTH_DEGRADED",
367 Self::WarningRetainedDiagnosticsDegraded => "ATM_WARNING_RETAINED_DIAGNOSTICS_DEGRADED",
368 Self::WarningSqliteHealthDegraded => "ATM_WARNING_SQLITE_HEALTH_DEGRADED",
369 Self::WarningOriginInboxEntrySkipped => "ATM_WARNING_ORIGIN_INBOX_ENTRY_SKIPPED",
370 Self::WarningMissingTeamConfigFallback => "ATM_WARNING_MISSING_TEAM_CONFIG_FALLBACK",
371 Self::WarningSendAlertStateDegraded => "ATM_WARNING_SEND_ALERT_STATE_DEGRADED",
372 Self::WarningIdentityDrift => "ATM_WARNING_IDENTITY_DRIFT",
373 Self::WarningRosterDrift => "ATM_WARNING_ROSTER_DRIFT",
374 Self::WarningHerdrUnnamedAgentTarget => "ATM_WARNING_HERDR_UNNAMED_AGENT_TARGET",
375 Self::WarningBaselineMemberMissing => "ATM_WARNING_BASELINE_MEMBER_MISSING",
376 Self::WarningRestoreInProgress => "ATM_WARNING_RESTORE_IN_PROGRESS",
377 Self::WarningStaleMailboxLock => "ATM_WARNING_STALE_MAILBOX_LOCK",
378 Self::WarningHookSkipped => "ATM_WARNING_HOOK_SKIPPED",
379 Self::WarningHookExecutionFailed => "ATM_WARNING_HOOK_EXECUTION_FAILED",
380 Self::RosterNoLead => "ATM_ROSTER_NO_LEAD",
381 Self::RosterMultipleLeads => "ATM_ROSTER_MULTIPLE_LEADS",
382 Self::RosterReservedName => "ATM_ROSTER_RESERVED_NAME",
383 Self::TaskStalled => "ATM_TASK_STALLED",
384 Self::MemberBlocked => "ATM_MEMBER_BLOCKED",
385 Self::RosterMixedLocalBackend => "ATM_ROSTER_MIXED_LOCAL_BACKEND",
386 Self::HerdrAgentNotVisible => "ATM_HERDR_AGENT_NOT_VISIBLE",
387 _ => return None,
388 })
389 }
390
391 fn post_send_or_misc_str(self) -> &'static str {
392 match self {
393 Self::PostSendPaneMissing => "ATM_POST_SEND_PANE_MISSING",
394 Self::PostSendTmuxSendFailed => "ATM_POST_SEND_TMUX_SEND_FAILED",
395 Self::PostSendHerdrPromptFailed => "ATM_POST_SEND_HERDR_PROMPT_FAILED",
396 Self::HerdrPromptFailed => "ATM_HERDR_PROMPT_FAILED",
397 Self::HerdrUnavailable => "ATM_HERDR_UNAVAILABLE",
398 Self::PostSendGraftUnavailable => "ATM_POST_SEND_GRAFT_UNAVAILABLE",
399 Self::GraftReceiverAlreadyActive => "ATM_GRAFT_RECEIVER_ALREADY_ACTIVE",
400 Self::GraftReceiverNotOwner => "ATM_GRAFT_RECEIVER_NOT_OWNER",
401 Self::GraftReceiverNotRegistered => "ATM_GRAFT_RECEIVER_NOT_REGISTERED",
402 Self::PostSendAdvisoryDeliveryFailed => "ATM_POST_SEND_ADVISORY_DELIVERY_FAILED",
403 Self::TestFakeTransportInjectionFailed => "ATM_TEST_FAKE_TRANSPORT_INJECTION_FAILED",
404 Self::HelpTopicNotFound => "ATM_HELP_TOPIC_NOT_FOUND",
405 Self::HookModuleInvalid => "ATM_HOOK_MODULE_INVALID",
406 Self::CronExprInvalid => "ATM_CRON_EXPR_INVALID",
407 Self::CronTriggerDelayInvalid => "ATM_CRON_TRIGGER_DELAY_INVALID",
408 Self::HookRefused => "ATM_HOOK_REFUSED",
409 Self::HookExit => "ATM_HOOK_EXIT",
410 Self::HookTimeout => "ATM_HOOK_TIMEOUT",
411 Self::HookMalformed => "ATM_HOOK_MALFORMED",
412 Self::StoreQueryFailed => "ATM_STORE_QUERY_FAILED",
413 Self::ToolSenderUnregistered => "ATM_TOOL_SENDER_UNREGISTERED",
414 Self::ToolSenderReserved => "ATM_TOOL_SENDER_RESERVED",
415 Self::ToolSenderUnauthorized => "ATM_TOOL_SENDER_UNAUTHORIZED",
416 Self::ToolKeyUnknown => "ATM_TOOL_KEY_UNKNOWN",
417 Self::ToolKeyRevoked => "ATM_TOOL_KEY_REVOKED",
418 Self::ToolNonceReplay => "ATM_TOOL_NONCE_REPLAY",
419 Self::ToolHostMismatch => "ATM_TOOL_HOST_MISMATCH",
420 Self::ToolGenerationConflict => "ATM_TOOL_GENERATION_CONFLICT",
421 Self::ToolSignatureInvalid => "ATM_TOOL_SIGNATURE_INVALID",
422 Self::ToolRequestExpired => "ATM_TOOL_REQUEST_EXPIRED",
423 Self::ToolCommitUncertain => "ATM_TOOL_COMMIT_UNCERTAIN",
424 _ => unreachable!("all AtmErrorCode variants must be covered by as_str helpers"),
425 }
426 }
427}
428
429impl FromStr for AtmErrorCode {
430 type Err = UnknownAtmErrorCode;
431
432 fn from_str(value: &str) -> Result<Self, Self::Err> {
433 parse_known_error_code(value).ok_or_else(|| UnknownAtmErrorCode(value.to_owned()))
434 }
435}
436
437fn parse_known_error_code(value: &str) -> Option<AtmErrorCode> {
438 parse_config_or_identity_code(value)
439 .or_else(|| parse_daemon_or_address_code(value))
440 .or_else(|| parse_mailbox_or_validation_code(value))
441 .or_else(|| parse_observability_or_warning_code(value))
442 .or_else(|| parse_post_send_or_misc_code(value))
443}
444
445fn parse_config_or_identity_code(value: &str) -> Option<AtmErrorCode> {
446 Some(match value {
447 "ATM_CONFIG_HOME_UNAVAILABLE" => AtmErrorCode::ConfigHomeUnavailable,
448 "ATM_HOME_UNRESOLVED" => AtmErrorCode::AtmHomeUnresolved,
449 "ATM_CONFIG_PARSE_FAILED" => AtmErrorCode::ConfigParseFailed,
450 "ATM_CONFIG_RETIRED_HOOK_MEMBERS_KEY" => AtmErrorCode::ConfigRetiredHookMembersKey,
451 "ATM_CONFIG_RETIRED_LEGACY_HOOK_KEYS" => AtmErrorCode::ConfigRetiredLegacyHookKeys,
452 "ATM_CONFIG_TEAM_PARSE_FAILED" => AtmErrorCode::ConfigTeamParseFailed,
453 "ATM_CONFIG_TEAM_MISSING" => AtmErrorCode::ConfigTeamMissing,
454 "ATM_IDENTITY_UNAVAILABLE" => AtmErrorCode::IdentityUnavailable,
455 "ATM_IDENTITY_INVALID" => AtmErrorCode::IdentityInvalid,
456 "ATM_IDENTITY_CONFLICT" => AtmErrorCode::IdentityConflict,
457 "ATM_MEMBER_ALREADY_EXISTS" => AtmErrorCode::MemberAlreadyExists,
458 "ATM_MEMBER_NOT_FOUND" => AtmErrorCode::MemberNotFound,
459 _ => return None,
460 })
461}
462
463fn parse_daemon_or_address_code(value: &str) -> Option<AtmErrorCode> {
464 Some(match value {
465 "ATM_DAEMON_UNAVAILABLE" => AtmErrorCode::DaemonUnavailable,
466 "ATM_RUNTIME_ROOT_INVALID" => AtmErrorCode::RuntimeRootInvalid,
467 "ATM_RUNTIME_BOOTSTRAP_REFUSED" => AtmErrorCode::RuntimeBootstrapRefused,
468 "ATM_SOCKET_OVERRIDE_FORBIDDEN" => AtmErrorCode::SocketOverrideForbidden,
469 "ATM_DAEMON_MAY_HAVE_EXECUTED" => AtmErrorCode::DaemonMayHaveExecuted,
470 "ATM_DAEMON_LIFECYCLE_WEDGE" => AtmErrorCode::DaemonLifecycleWedge,
471 "ATM_DAEMON_LAUNCH_GATE_REJECTED" => AtmErrorCode::DaemonLaunchGateRejected,
472 "ATM_DAEMON_SERVING_STATE_REJECTED" => AtmErrorCode::DaemonServingStateRejected,
473 "ATM_DAEMON_STALE_OWNER_RECOVERY_FAILED" => AtmErrorCode::DaemonStaleOwnerRecoveryFailed,
474 "ATM_DAEMON_AUTO_START_FAILED" => AtmErrorCode::DaemonAutoStartFailed,
475 "ATM_DAEMON_CONNECTION_SATURATED" => AtmErrorCode::DaemonConnectionSaturated,
476 "ATM_BLOCKING_BRIDGE_DEADLINE_BEFORE_START" => {
477 AtmErrorCode::BlockingBridgeDeadlineBeforeStart
478 }
479 "ATM_BLOCKING_BRIDGE_DEADLINE_AFTER_START" => {
480 AtmErrorCode::BlockingBridgeDeadlineAfterStart
481 }
482 "REMOTE_DELIVERY_UNCONFIRMED" => AtmErrorCode::RemoteDeliveryUnconfirmed,
483 "ATM_PEER_WIRE_MODE_INVALID" => AtmErrorCode::PeerWireModeInvalid,
484 "ATM_PEER_WIRE_MODE_SOURCE_FORBIDDEN" => AtmErrorCode::PeerWireModeSourceForbidden,
485 "ATM_PEER_WIRE_PLAINTEXT_AUTHENTICATION_REQUIRED" => {
486 AtmErrorCode::PeerWirePlaintextAuthenticationRequired
487 }
488 "ATM_PEER_CONFIG_VALIDATION_FAILED" => AtmErrorCode::PeerConfigValidationFailed,
489 "ATM_CERTIFICATE_OPERATION_FAILED" => AtmErrorCode::CertificateOperationFailed,
490 "ATM_PEER_AUTHENTICATION_FAILED" => AtmErrorCode::PeerAuthenticationFailed,
491 "ATM_TRANSPORT_TIMEOUT" => AtmErrorCode::TransportTimeout,
492 "ATM_TRANSPORT_PROTOCOL_FAILED" => AtmErrorCode::TransportProtocolFailed,
493 "ATM_BIND_PREFLIGHT_FAILED" => AtmErrorCode::BindPreflightFailed,
494 "ATM_CLIENT_DAEMON_VERSION_INCOMPATIBLE" => AtmErrorCode::ClientDaemonVersionIncompatible,
495 "ATM_DAEMON_ADVISORY_SESSION_ALREADY_REGISTERED" => {
496 AtmErrorCode::DaemonAdvisorySessionAlreadyRegistered
497 }
498 "ATM_DAEMON_ADVISORY_SESSION_NOT_REGISTERED" => {
499 AtmErrorCode::DaemonAdvisorySessionNotRegistered
500 }
501 "ATM_DAEMON_ADVISORY_SESSION_CLEANUP_FAILED" => {
502 AtmErrorCode::DaemonAdvisorySessionCleanupFailed
503 }
504 "ATM_ADDRESS_PARSE_FAILED" => AtmErrorCode::AddressParseFailed,
505 "ATM_TEAM_UNAVAILABLE" => AtmErrorCode::TeamUnavailable,
506 "ATM_TEAM_INVALID" => AtmErrorCode::TeamInvalid,
507 "ATM_TEAM_NOT_FOUND" => AtmErrorCode::TeamNotFound,
508 "ATM_AGENT_NOT_FOUND" => AtmErrorCode::AgentNotFound,
509 _ => return None,
510 })
511}
512
513fn parse_mailbox_or_validation_code(value: &str) -> Option<AtmErrorCode> {
514 Some(match value {
515 "ATM_MAILBOX_READ_FAILED" => AtmErrorCode::MailboxReadFailed,
516 "ATM_MAILBOX_WRITE_FAILED" => AtmErrorCode::MailboxWriteFailed,
517 "ATM_MAILBOX_LOCK_FAILED" => AtmErrorCode::MailboxLockFailed,
518 "ATM_MAILBOX_LOCK_READ_ONLY_FILESYSTEM" => AtmErrorCode::MailboxLockReadOnlyFilesystem,
519 "ATM_MAILBOX_LOCK_TIMEOUT" => AtmErrorCode::MailboxLockTimeout,
520 "ATM_INTERNAL_ERROR" => AtmErrorCode::InternalError,
521 "ATM_MESSAGE_VALIDATION_FAILED" => AtmErrorCode::MessageValidationFailed,
522 "ATM_TASK_NOT_FOUND" => AtmErrorCode::TaskNotFound,
523 "ATM_TASK_ALREADY_ACTIVE" => AtmErrorCode::TaskAlreadyActive,
524 "ATM_TASK_ALREADY_CLOSED" => AtmErrorCode::TaskAlreadyClosed,
525 "ATM_TASK_NOT_COUNTERPARTY" => AtmErrorCode::TaskNotCounterparty,
526 "ATM_TASK_STALE_COUNTERPARTY" => AtmErrorCode::TaskStaleCounterparty,
527 "ATM_TASK_MOVE_INVALID" => AtmErrorCode::TaskMoveInvalid,
528 "ATM_TASK_MAX_ACTIVE_REACHED" => AtmErrorCode::TaskMaxActiveReached,
529 "ATM_SEARCH_LOCAL_ONLY" => AtmErrorCode::SearchLocalOnly,
530 "ATM_LOCAL_HTTP_CAPABILITY_INVALID" => AtmErrorCode::LocalHttpCapabilityInvalid,
531 "ATM_LOCAL_HTTP_ENDPOINT_SCHEMA_UNSUPPORTED" => {
532 AtmErrorCode::LocalHttpEndpointSchemaUnsupported
533 }
534 "ATM_LOCAL_HTTP_ENDPOINT_MISSING" => AtmErrorCode::LocalHttpEndpointMissing,
535 "ATM_LOCAL_HTTP_ENDPOINT_NON_LOOPBACK" => AtmErrorCode::LocalHttpEndpointNonLoopback,
536 "ATM_LOCAL_HTTP_RUNTIME_DIRECTORY_MISSING" => {
537 AtmErrorCode::LocalHttpRuntimeDirectoryMissing
538 }
539 "ATM_LOCAL_HTTP_CAPABILITY_REVOKED" => AtmErrorCode::LocalHttpCapabilityRevoked,
540 "ATM_MESSAGE_ID_CONFLICT" => AtmErrorCode::MessageIdConflict,
541 "ATM_SELF_ADDRESSED_SEND_INVALID" => AtmErrorCode::SelfAddressedSendInvalid,
542 "ATM_NUDGE_TEMPLATE_BODY_EMPTY" => AtmErrorCode::EmptyNudgeTemplateBody,
543 "ATM_CALLER_CONTEXT_REQUEST_INVALID" => AtmErrorCode::CallerContextRequestInvalid,
544 "TEMPLATE_CONTENT_NOT_UTF8" => AtmErrorCode::TemplateContentNotUtf8,
545 "DECOMPOSED_TEMPLATE_INCLUDE_FORBIDDEN" => AtmErrorCode::DecomposedTemplateIncludeForbidden,
546 "TEMPLATE_LOAD_FAILED" => AtmErrorCode::TemplateLoadFailed,
547 "TEMPLATE_HASH_API_FAILED" => AtmErrorCode::TemplateHashApiFailed,
548 "TEMPLATE_INSPECTION_PARSE_FAILED" => AtmErrorCode::TemplateInspectionParseFailed,
549 "TEMPLATE_REQUIRED_VARIABLE_MISSING" => AtmErrorCode::TemplateRequiredVariableMissing,
550 "TEMPLATE_VARIABLE_RESOLUTION_FAILED" => AtmErrorCode::TemplateVariableResolutionFailed,
551 "TEMPLATE_RENDER_VERIFICATION_FAILED" => AtmErrorCode::TemplateRenderVerificationFailed,
552 "TEMPLATE_INCLUDE_UNRESOLVED" => AtmErrorCode::TemplateIncludeUnresolved,
553 "TEMPLATE_CLASSIFICATION_INVALID" => AtmErrorCode::TemplateClassificationInvalid,
554 "TEMPLATE_WORKFLOW_INVALID" => AtmErrorCode::TemplateWorkflowInvalid,
555 "TEMPLATE_WORKFLOW_VALUE_INVALID" => AtmErrorCode::TemplateWorkflowValueInvalid,
556 "TEMPLATE_TAG_RESERVED" => AtmErrorCode::TemplateTagReserved,
557 "ATM_WORKFLOW_QUERY_INVALID" => AtmErrorCode::WorkflowQueryInvalid,
558 "ATM_WORKFLOW_TELEMETRY_CONFIG_INVALID" => AtmErrorCode::WorkflowTelemetryConfigInvalid,
559 "ATM_TELEMETRY_EXPORT_CONFIG_INVALID" => AtmErrorCode::TelemetryExportConfigInvalid,
560 "ATM_WORKFLOW_TELEMETRY_DROPPED" => AtmErrorCode::WorkflowTelemetryDropped,
561 "ATM_SERIALIZATION_FAILED" => AtmErrorCode::SerializationFailed,
562 "ATM_FILE_POLICY_REJECTED" => AtmErrorCode::FilePolicyRejected,
563 "ATM_FILE_REFERENCE_REWRITE_FAILED" => AtmErrorCode::FileReferenceRewriteFailed,
564 "ATM_WAIT_TIMEOUT" => AtmErrorCode::WaitTimeout,
565 "ATM_ACK_INVALID_STATE" => AtmErrorCode::AckInvalidState,
566 "ATM_CLEAR_INVALID_STATE" => AtmErrorCode::ClearInvalidState,
567 _ => return None,
568 })
569}
570
571fn parse_observability_or_warning_code(value: &str) -> Option<AtmErrorCode> {
572 Some(match value {
573 "ATM_OBSERVABILITY_EMIT_FAILED" => AtmErrorCode::ObservabilityEmitFailed,
574 "ATM_OBSERVABILITY_QUERY_FAILED" => AtmErrorCode::ObservabilityQueryFailed,
575 "ATM_OBSERVABILITY_FOLLOW_FAILED" => AtmErrorCode::ObservabilityFollowFailed,
576 "ATM_OBSERVABILITY_HEALTH_FAILED" => AtmErrorCode::ObservabilityHealthFailed,
577 "ATM_OBSERVABILITY_BOOTSTRAP_FAILED" => AtmErrorCode::ObservabilityBootstrapFailed,
578 "ATM_OBSERVABILITY_HEALTH_OK" => AtmErrorCode::ObservabilityHealthOk,
579 "ATM_RETAINED_DIAGNOSTICS_HEALTH_OK" => AtmErrorCode::RetainedDiagnosticsHealthOk,
580 "ATM_WARNING_INVALID_TEAM_MEMBER_SKIPPED" => AtmErrorCode::WarningInvalidTeamMemberSkipped,
581 "ATM_WARNING_MAILBOX_RECORD_SKIPPED" => AtmErrorCode::WarningMailboxRecordSkipped,
582 "ATM_WARNING_MALFORMED_ATM_FIELD_IGNORED" => AtmErrorCode::WarningMalformedAtmFieldIgnored,
583 "ATM_WARNING_OBSERVABILITY_HEALTH_DEGRADED" => {
584 AtmErrorCode::WarningObservabilityHealthDegraded
585 }
586 "ATM_WARNING_RETAINED_DIAGNOSTICS_DEGRADED" => {
587 AtmErrorCode::WarningRetainedDiagnosticsDegraded
588 }
589 "ATM_WARNING_SQLITE_HEALTH_DEGRADED" => AtmErrorCode::WarningSqliteHealthDegraded,
590 "ATM_WARNING_ORIGIN_INBOX_ENTRY_SKIPPED" => AtmErrorCode::WarningOriginInboxEntrySkipped,
591 "ATM_WARNING_MISSING_TEAM_CONFIG_FALLBACK" => {
592 AtmErrorCode::WarningMissingTeamConfigFallback
593 }
594 "ATM_WARNING_SEND_ALERT_STATE_DEGRADED" => AtmErrorCode::WarningSendAlertStateDegraded,
595 "ATM_WARNING_IDENTITY_DRIFT" => AtmErrorCode::WarningIdentityDrift,
596 "ATM_WARNING_ROSTER_DRIFT" => AtmErrorCode::WarningRosterDrift,
597 "ATM_WARNING_HERDR_UNNAMED_AGENT_TARGET" => AtmErrorCode::WarningHerdrUnnamedAgentTarget,
598 "ATM_WARNING_BASELINE_MEMBER_MISSING" => AtmErrorCode::WarningBaselineMemberMissing,
599 "ATM_WARNING_RESTORE_IN_PROGRESS" => AtmErrorCode::WarningRestoreInProgress,
600 "ATM_WARNING_STALE_MAILBOX_LOCK" => AtmErrorCode::WarningStaleMailboxLock,
601 "ATM_WARNING_HOOK_SKIPPED" => AtmErrorCode::WarningHookSkipped,
602 "ATM_WARNING_HOOK_EXECUTION_FAILED" => AtmErrorCode::WarningHookExecutionFailed,
603 "ATM_ROSTER_NO_LEAD" => AtmErrorCode::RosterNoLead,
604 "ATM_ROSTER_MULTIPLE_LEADS" => AtmErrorCode::RosterMultipleLeads,
605 "ATM_ROSTER_RESERVED_NAME" => AtmErrorCode::RosterReservedName,
606 "ATM_TASK_STALLED" => AtmErrorCode::TaskStalled,
607 "ATM_MEMBER_BLOCKED" => AtmErrorCode::MemberBlocked,
608 "ATM_ROSTER_MIXED_LOCAL_BACKEND" => AtmErrorCode::RosterMixedLocalBackend,
609 "ATM_HERDR_AGENT_NOT_VISIBLE" => AtmErrorCode::HerdrAgentNotVisible,
610 _ => return None,
611 })
612}
613
614fn parse_post_send_or_misc_code(value: &str) -> Option<AtmErrorCode> {
615 Some(match value {
616 "ATM_POST_SEND_PANE_MISSING" => AtmErrorCode::PostSendPaneMissing,
617 "ATM_POST_SEND_TMUX_SEND_FAILED" => AtmErrorCode::PostSendTmuxSendFailed,
618 "ATM_POST_SEND_HERDR_PROMPT_FAILED" => AtmErrorCode::PostSendHerdrPromptFailed,
619 "ATM_HERDR_PROMPT_FAILED" => AtmErrorCode::HerdrPromptFailed,
620 "ATM_HERDR_UNAVAILABLE" => AtmErrorCode::HerdrUnavailable,
621 "ATM_POST_SEND_GRAFT_UNAVAILABLE" => AtmErrorCode::PostSendGraftUnavailable,
622 "ATM_GRAFT_RECEIVER_ALREADY_ACTIVE" => AtmErrorCode::GraftReceiverAlreadyActive,
623 "ATM_GRAFT_RECEIVER_NOT_OWNER" => AtmErrorCode::GraftReceiverNotOwner,
624 "ATM_GRAFT_RECEIVER_NOT_REGISTERED" => AtmErrorCode::GraftReceiverNotRegistered,
625 "ATM_POST_SEND_ADVISORY_DELIVERY_FAILED" => AtmErrorCode::PostSendAdvisoryDeliveryFailed,
626 "ATM_TEST_FAKE_TRANSPORT_INJECTION_FAILED" => {
627 AtmErrorCode::TestFakeTransportInjectionFailed
628 }
629 "ATM_HELP_TOPIC_NOT_FOUND" => AtmErrorCode::HelpTopicNotFound,
630 "ATM_HOOK_MODULE_INVALID" => AtmErrorCode::HookModuleInvalid,
631 "ATM_CRON_EXPR_INVALID" => AtmErrorCode::CronExprInvalid,
632 "ATM_CRON_TRIGGER_DELAY_INVALID" => AtmErrorCode::CronTriggerDelayInvalid,
633 "ATM_HOOK_REFUSED" => AtmErrorCode::HookRefused,
634 "ATM_HOOK_EXIT" => AtmErrorCode::HookExit,
635 "ATM_HOOK_TIMEOUT" => AtmErrorCode::HookTimeout,
636 "ATM_HOOK_MALFORMED" => AtmErrorCode::HookMalformed,
637 "ATM_STORE_QUERY_FAILED" => AtmErrorCode::StoreQueryFailed,
638 "ATM_TOOL_SENDER_UNREGISTERED" => AtmErrorCode::ToolSenderUnregistered,
639 "ATM_TOOL_SENDER_RESERVED" => AtmErrorCode::ToolSenderReserved,
640 "ATM_TOOL_SENDER_UNAUTHORIZED" => AtmErrorCode::ToolSenderUnauthorized,
641 "ATM_TOOL_KEY_UNKNOWN" => AtmErrorCode::ToolKeyUnknown,
642 "ATM_TOOL_KEY_REVOKED" => AtmErrorCode::ToolKeyRevoked,
643 "ATM_TOOL_NONCE_REPLAY" => AtmErrorCode::ToolNonceReplay,
644 "ATM_TOOL_HOST_MISMATCH" => AtmErrorCode::ToolHostMismatch,
645 "ATM_TOOL_GENERATION_CONFLICT" => AtmErrorCode::ToolGenerationConflict,
646 "ATM_TOOL_SIGNATURE_INVALID" => AtmErrorCode::ToolSignatureInvalid,
647 "ATM_TOOL_REQUEST_EXPIRED" => AtmErrorCode::ToolRequestExpired,
648 "ATM_TOOL_COMMIT_UNCERTAIN" => AtmErrorCode::ToolCommitUncertain,
649 _ => return None,
650 })
651}
652
653impl fmt::Display for AtmErrorCode {
654 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
655 f.write_str(self.as_str())
656 }
657}
658
659impl Serialize for AtmErrorCode {
660 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
661 where
662 S: serde::Serializer,
663 {
664 serializer.serialize_str(self.as_str())
665 }
666}
667
668impl<'de> Deserialize<'de> for AtmErrorCode {
669 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
670 where
671 D: Deserializer<'de>,
672 {
673 let value = String::deserialize(deserializer)?;
674 value.parse().map_err(serde::de::Error::custom)
675 }
676}