causa_runtime/executor/error.rs
1use causa_kernel::{
2 BatchError, BlockId, ControlError, ProcessorError, SourceError, ToolResultPayload,
3};
4
5/// Failure to construct or change a tool registry.
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7pub enum ToolRegistryError {
8 /// Static tool definitions must have distinct names.
9 #[error("duplicate static tool: {name}")]
10 DuplicateTool {
11 /// Conflicting advertised name.
12 name: String,
13 },
14 /// A source with this identity is already registered.
15 #[error("dynamic source already registered: {source_id}")]
16 DuplicateSource {
17 /// Conflicting source identity.
18 source_id: String,
19 },
20 /// A requested source is not registered.
21 #[error("no dynamic source registered: {source_id}")]
22 UnknownSource {
23 /// Requested source identity.
24 source_id: String,
25 },
26}
27
28/// Failure to bind a complete, unambiguous invocation catalog.
29#[derive(Debug, thiserror::Error)]
30pub enum ToolCatalogError {
31 /// The parent invocation control stopped catalog acquisition.
32 #[error(transparent)]
33 Control(ControlError),
34 /// A catalog could not be listed; its original error is retained.
35 #[error("source {source_id} failed: {error}")]
36 Source {
37 /// Identity of the failed source registration.
38 source_id: String,
39 /// Original listing failure.
40 error: SourceError,
41 },
42 /// A name occurred more than once in the assembled catalog.
43 #[error("duplicate advertised tool: {name}")]
44 DuplicateTool {
45 /// Conflicting advertised name.
46 name: String,
47 },
48 /// A static tool changed the name registered at construction.
49 #[error("static tool name changed from {registered} to {actual}")]
50 StaticNameChanged {
51 /// Name registered at construction.
52 registered: String,
53 /// Name returned during this binding.
54 actual: String,
55 },
56}
57
58/// Position of a processor in the executor's fixed processing flow.
59#[derive(Debug, Clone, Copy, PartialEq, Eq)]
60pub enum ToolProcessorPhase {
61 /// Before dispatch; pending inputs may be changed or completed.
62 Before,
63 /// After dispatch; completed output may be edited or reordered.
64 After,
65}
66
67/// Why controlled processing returned the caller's current batch early.
68// The confirmed API retains the actual rejected payload without indirection.
69#[allow(clippy::large_enum_variant)]
70#[derive(Debug, thiserror::Error)]
71pub enum ToolProcessingError {
72 /// The binding's parent cancellation or deadline stopped processing.
73 #[error(transparent)]
74 Control(ControlError),
75 /// The input or internally produced batch is structurally invalid.
76 #[error("invalid tool batch: {0}")]
77 InvalidBatch(BatchError),
78 /// This entry point only accepts new, entirely pending declarations.
79 #[error("tool batch already contains {completed} completed calls")]
80 NotFreshBatch {
81 /// Number of completed calls at entry.
82 completed: usize,
83 },
84 /// A processor returned its own error.
85 #[error("{phase:?} processor {index} failed: {error}")]
86 Processor {
87 /// Processing phase.
88 phase: ToolProcessorPhase,
89 /// Zero-based index within that phase's configured processors.
90 index: usize,
91 /// Original processor error.
92 error: ProcessorError,
93 },
94 /// A processor returned a structurally invalid batch.
95 #[error("{phase:?} processor {index} returned an invalid batch: {error}")]
96 InvalidProcessorBatch {
97 /// Processing phase.
98 phase: ToolProcessorPhase,
99 /// Zero-based processor index.
100 index: usize,
101 /// Original batch validation error.
102 error: BatchError,
103 },
104 /// A processor violated fixed membership or immutable completed facts.
105 #[error("{phase:?} processor {index} violated its handoff: {message}")]
106 Handoff {
107 /// Processing phase.
108 phase: ToolProcessorPhase,
109 /// Zero-based processor index.
110 index: usize,
111 /// Specific violated handoff constraint.
112 message: String,
113 },
114 /// An actual tool result could not be associated with its declaration.
115 #[error("tool result rejected for declaration {call_block_id:?}: {error}")]
116 ResultRejected {
117 /// Declaration actually dispatched.
118 call_block_id: BlockId,
119 /// Original association or installation error.
120 error: BatchError,
121 /// Actual rejected payload, preserved for diagnosis.
122 result: ToolResultPayload,
123 },
124}