Skip to main content

icydb_core/error/
mod.rs

1//! Module: error
2//!
3//! Defines the canonical runtime error taxonomy for `icydb-core`.
4//! This module owns the shared error classes, origins, details, and
5//! constructor entry points used across storage, planning, execution, and
6//! serialization boundaries.
7
8#[cfg(test)]
9mod tests;
10
11use icydb_diagnostic_code as diagnostic_code;
12use std::fmt;
13use thiserror::Error as ThisError;
14
15// ============================================================================
16// INTERNAL ERROR TAXONOMY — ARCHITECTURAL CONTRACT
17// ============================================================================
18//
19// This file defines the canonical runtime error classification system for
20// icydb-core. It is the single source of truth for:
21//
22//   • ErrorClass   (semantic domain)
23//   • ErrorOrigin  (subsystem boundary)
24//   • Structured detail payloads
25//   • Canonical constructor entry points
26//
27// -----------------------------------------------------------------------------
28// DESIGN INTENT
29// -----------------------------------------------------------------------------
30//
31// 1. InternalError is a *taxonomy carrier*, not a formatting utility.
32//
33//    - ErrorClass represents semantic meaning (corruption, invariant_violation,
34//      unsupported, etc).
35//    - ErrorOrigin represents the subsystem boundary (store, index, query,
36//      executor, serialize, interface, etc).
37//    - The (class, origin) pair must remain stable and intentional.
38//
39// 2. Call sites MUST prefer canonical constructors.
40//
41//    Do NOT construct errors manually via:
42//        InternalError::new(class, origin, ...)
43//    unless you are defining a new canonical helper here.
44//
45//    If a pattern appears more than once, centralize it here.
46//
47// 3. Constructors in this file must represent real architectural boundaries.
48//
49//    Add a new helper ONLY if it:
50//
51//      • Encodes a cross-cutting invariant,
52//      • Represents a subsystem boundary,
53//      • Or prevents taxonomy drift across call sites.
54//
55//    Do NOT add feature-specific helpers.
56//    Do NOT add one-off formatting helpers.
57//    Do NOT turn this file into a generic message factory.
58//
59// 4. ErrorDetail must align with ErrorOrigin.
60//
61//    If detail is present, it MUST correspond to the origin.
62//    Do not attach mismatched detail variants.
63//
64// 5. Plan-layer errors are NOT runtime failures.
65//
66//    PlanError and CursorPlanError must be translated into
67//    executor/query invariants via the canonical mapping functions.
68//    Do not leak plan-layer error types across execution boundaries.
69//
70// 6. Preserve taxonomy stability.
71//
72//    Do NOT:
73//      • Merge error classes.
74//      • Reclassify corruption as internal.
75//      • Downgrade invariant violations.
76//      • Introduce ambiguous class/origin combinations.
77//
78//    Any change to ErrorClass or ErrorOrigin is an architectural change
79//    and must be reviewed accordingly.
80//
81// -----------------------------------------------------------------------------
82// NON-GOALS
83// -----------------------------------------------------------------------------
84//
85// This is NOT:
86//
87//   • A public API contract.
88//   • A generic error abstraction layer.
89//   • A feature-specific message builder.
90//   • A dumping ground for temporary error conversions.
91//
92// -----------------------------------------------------------------------------
93// MAINTENANCE GUIDELINES
94// -----------------------------------------------------------------------------
95//
96// When modifying this file:
97//
98//   1. Ensure classification semantics remain consistent.
99//   2. Avoid constructor proliferation.
100//   3. Prefer narrow, origin-specific helpers over ad-hoc new(...).
101//   4. Keep formatting minimal and standardized.
102//   5. Keep this file boring and stable.
103//
104// If this file grows rapidly, something is wrong at the call sites.
105//
106// ============================================================================
107
108///
109/// InternalError
110///
111/// Structured runtime error with a stable internal classification.
112/// Not a stable API; intended for internal use and may change without notice.
113///
114
115#[derive(Debug, ThisError)]
116#[error("{message}")]
117pub struct InternalError {
118    pub(crate) class: ErrorClass,
119    pub(crate) origin: ErrorOrigin,
120    pub(crate) message: String,
121
122    /// Optional structured error detail.
123    /// The variant (if present) must correspond to `origin`.
124    pub(crate) detail: Option<ErrorDetail>,
125}
126
127impl InternalError {
128    /// Construct an InternalError with optional origin-specific detail.
129    /// This constructor provides default StoreError details for certain
130    /// (class, origin) combinations but does not guarantee a detail payload.
131    #[cold]
132    #[inline(never)]
133    pub fn new(class: ErrorClass, origin: ErrorOrigin, message: impl Into<String>) -> Self {
134        let message = message.into();
135
136        let detail = match (class, origin) {
137            (ErrorClass::Corruption, ErrorOrigin::Store) => {
138                Some(ErrorDetail::Store(StoreError::Corrupt {
139                    message: message.clone(),
140                }))
141            }
142            (ErrorClass::InvariantViolation, ErrorOrigin::Store) => {
143                Some(ErrorDetail::Store(StoreError::InvariantViolation {
144                    message: message.clone(),
145                }))
146            }
147            _ => None,
148        };
149
150        Self {
151            class,
152            origin,
153            message,
154            detail,
155        }
156    }
157
158    /// Return the internal error class taxonomy.
159    #[must_use]
160    pub const fn class(&self) -> ErrorClass {
161        self.class
162    }
163
164    /// Return the internal error origin taxonomy.
165    #[must_use]
166    pub const fn origin(&self) -> ErrorOrigin {
167        self.origin
168    }
169
170    /// Return the rendered internal error message.
171    #[must_use]
172    pub fn message(&self) -> &str {
173        &self.message
174    }
175
176    /// Return the optional structured detail payload.
177    #[must_use]
178    pub const fn detail(&self) -> Option<&ErrorDetail> {
179        self.detail.as_ref()
180    }
181
182    /// Return compact diagnostic identity for this internal error.
183    #[must_use]
184    pub fn diagnostic(&self) -> diagnostic_code::Diagnostic {
185        diagnostic_code::Diagnostic::new(
186            self.diagnostic_code(),
187            self.origin.diagnostic_origin(),
188            self.detail
189                .as_ref()
190                .and_then(ErrorDetail::diagnostic_detail),
191        )
192    }
193
194    /// Return the compact diagnostic code for this internal error.
195    #[must_use]
196    pub fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
197        self.detail.as_ref().map_or_else(
198            || self.class.diagnostic_code(self.origin),
199            ErrorDetail::diagnostic_code,
200        )
201    }
202
203    /// Consume and return the rendered internal error message.
204    #[must_use]
205    pub fn into_message(self) -> String {
206        self.message
207    }
208
209    /// Construct an error while preserving an explicit class/origin taxonomy pair.
210    #[cold]
211    #[inline(never)]
212    pub(crate) fn classified(
213        class: ErrorClass,
214        origin: ErrorOrigin,
215        message: impl Into<String>,
216    ) -> Self {
217        Self::new(class, origin, message)
218    }
219
220    /// Rebuild this error with a new message while preserving class/origin taxonomy.
221    #[cold]
222    #[inline(never)]
223    pub(crate) fn with_message(self, message: impl Into<String>) -> Self {
224        Self::classified(self.class, self.origin, message)
225    }
226
227    /// Rebuild this error with a new origin while preserving class/message.
228    ///
229    /// Origin-scoped detail payloads are intentionally dropped when re-origining.
230    #[cold]
231    #[inline(never)]
232    pub(crate) fn with_origin(self, origin: ErrorOrigin) -> Self {
233        Self::classified(self.class, origin, self.message)
234    }
235
236    /// Construct an index-origin invariant violation.
237    #[cold]
238    #[inline(never)]
239    pub(crate) fn index_invariant(message: impl Into<String>) -> Self {
240        Self::new(
241            ErrorClass::InvariantViolation,
242            ErrorOrigin::Index,
243            message.into(),
244        )
245    }
246
247    /// Construct the canonical index field-count invariant for key building.
248    pub(crate) fn index_key_field_count_exceeds_max(
249        index_name: &str,
250        field_count: usize,
251        max_fields: usize,
252    ) -> Self {
253        Self::index_invariant(format!(
254            "index '{index_name}' has {field_count} fields (max {max_fields})",
255        ))
256    }
257
258    /// Construct the canonical index-key source-field-missing-on-model invariant.
259    pub(crate) fn index_key_item_field_missing_on_entity_model(field: &str) -> Self {
260        Self::index_invariant(format!(
261            "index key item field missing on entity model: {field}",
262        ))
263    }
264
265    /// Construct the canonical index-key source-field-missing-on-row invariant.
266    pub(crate) fn index_key_item_field_missing_on_lookup_row(field: &str) -> Self {
267        Self::index_invariant(format!(
268            "index key item field missing on lookup row: {field}",
269        ))
270    }
271
272    /// Construct the canonical index-expression source-type mismatch invariant.
273    pub(crate) fn index_expression_source_type_mismatch(
274        index_name: &str,
275        expression: impl fmt::Display,
276        expected: &str,
277        source_label: &str,
278    ) -> Self {
279        Self::index_invariant(format!(
280            "index '{index_name}' expression '{expression}' expected {expected} source value, got {source_label}",
281        ))
282    }
283
284    /// Construct a planner-origin invariant violation with the canonical
285    /// executor-boundary invariant prefix preserved in the message payload.
286    #[cold]
287    #[inline(never)]
288    pub(crate) fn planner_executor_invariant(reason: impl Into<String>) -> Self {
289        Self::new(
290            ErrorClass::InvariantViolation,
291            ErrorOrigin::Planner,
292            Self::executor_invariant_message(reason),
293        )
294    }
295
296    /// Construct a query-origin invariant violation with the canonical
297    /// executor-boundary invariant prefix preserved in the message payload.
298    #[cold]
299    #[inline(never)]
300    pub(crate) fn query_executor_invariant(reason: impl Into<String>) -> Self {
301        Self::new(
302            ErrorClass::InvariantViolation,
303            ErrorOrigin::Query,
304            Self::executor_invariant_message(reason),
305        )
306    }
307
308    /// Construct a cursor-origin invariant violation with the canonical
309    /// executor-boundary invariant prefix preserved in the message payload.
310    #[cold]
311    #[inline(never)]
312    pub(crate) fn cursor_executor_invariant(reason: impl Into<String>) -> Self {
313        Self::new(
314            ErrorClass::InvariantViolation,
315            ErrorOrigin::Cursor,
316            Self::executor_invariant_message(reason),
317        )
318    }
319
320    /// Construct an executor-origin invariant violation.
321    #[cold]
322    #[inline(never)]
323    pub(crate) fn executor_invariant(message: impl Into<String>) -> Self {
324        Self::new(
325            ErrorClass::InvariantViolation,
326            ErrorOrigin::Executor,
327            message.into(),
328        )
329    }
330
331    /// Construct an executor-origin internal error.
332    #[cold]
333    #[inline(never)]
334    pub(crate) fn executor_internal(message: impl Into<String>) -> Self {
335        Self::new(ErrorClass::Internal, ErrorOrigin::Executor, message.into())
336    }
337
338    /// Construct an executor-origin unsupported error.
339    #[cold]
340    #[inline(never)]
341    pub(crate) fn executor_unsupported(message: impl Into<String>) -> Self {
342        Self::new(
343            ErrorClass::Unsupported,
344            ErrorOrigin::Executor,
345            message.into(),
346        )
347    }
348
349    /// Construct an executor-origin save-preflight primary-key missing invariant.
350    pub(crate) fn mutation_entity_primary_key_missing(entity_path: &str, field_name: &str) -> Self {
351        Self::executor_invariant(format!(
352            "entity primary key field missing: {entity_path} field={field_name}",
353        ))
354    }
355
356    /// Construct an executor-origin save-preflight primary-key invalid-value invariant.
357    pub(crate) fn mutation_entity_primary_key_invalid_value(
358        entity_path: &str,
359        field_name: &str,
360        value: &crate::value::Value,
361    ) -> Self {
362        Self::executor_invariant(format!(
363            "entity primary key field has invalid value: {entity_path} field={field_name} value={value:?}",
364        ))
365    }
366
367    /// Construct an executor-origin save-preflight primary-key type mismatch invariant.
368    pub(crate) fn mutation_entity_primary_key_type_mismatch(
369        entity_path: &str,
370        field_name: &str,
371        value: &crate::value::Value,
372    ) -> Self {
373        Self::executor_invariant(format!(
374            "entity primary key field type mismatch: {entity_path} field={field_name} value={value:?}",
375        ))
376    }
377
378    /// Construct an executor-origin save-preflight primary-key identity mismatch invariant.
379    pub(crate) fn mutation_entity_primary_key_mismatch(
380        entity_path: &str,
381        field_name: &str,
382        field_value: &crate::value::Value,
383        identity_key: &crate::value::Value,
384    ) -> Self {
385        Self::executor_invariant(format!(
386            "entity primary key mismatch: {entity_path} field={field_name} field_value={field_value:?} id_key={identity_key:?}",
387        ))
388    }
389
390    /// Construct an executor-origin save-preflight field-missing invariant.
391    pub(crate) fn mutation_entity_field_missing(
392        entity_path: &str,
393        field_name: &str,
394        indexed: bool,
395    ) -> Self {
396        let indexed_note = if indexed { " (indexed)" } else { "" };
397
398        Self::executor_invariant(format!(
399            "entity field missing: {entity_path} field={field_name}{indexed_note}",
400        ))
401    }
402
403    /// Construct an executor-origin sparse structural patch required-field invariant.
404    pub(crate) fn mutation_structural_patch_required_field_missing(
405        entity_path: &str,
406        field_name: &str,
407    ) -> Self {
408        Self::executor_invariant(format!(
409            "structural patch missing required field: {entity_path} field={field_name}",
410        ))
411    }
412
413    /// Construct an executor-origin save-preflight field-type mismatch invariant.
414    pub(crate) fn mutation_entity_field_type_mismatch(
415        entity_path: &str,
416        field_name: &str,
417        value: &crate::value::Value,
418    ) -> Self {
419        Self::executor_invariant(format!(
420            "entity field type mismatch: {entity_path} field={field_name} value={value:?}",
421        ))
422    }
423
424    /// Construct an executor-origin generated-field authored-write rejection.
425    pub(crate) fn mutation_generated_field_explicit(entity_path: &str, field_name: &str) -> Self {
426        Self::executor_unsupported(format!(
427            "generated field may not be explicitly written: {entity_path} field={field_name}",
428        ))
429    }
430
431    /// Construct an executor-origin typed create omission rejection.
432    #[must_use]
433    pub fn mutation_create_missing_authored_fields(entity_path: &str, field_names: &str) -> Self {
434        Self::executor_unsupported(format!(
435            "create requires explicit values for authorable fields {field_names}: {entity_path}",
436        ))
437    }
438
439    /// Construct an executor-origin mutation result invariant.
440    ///
441    /// This constructor lands ahead of the public structural mutation surface,
442    /// so the library target may not route through it until that caller exists.
443    pub(crate) fn mutation_structural_after_image_invalid(
444        entity_path: &str,
445        data_key: impl fmt::Display,
446        detail: impl AsRef<str>,
447    ) -> Self {
448        Self::executor_invariant(format!(
449            "mutation result is invalid: {entity_path} key={data_key} ({})",
450            detail.as_ref(),
451        ))
452    }
453
454    /// Construct an executor-origin mutation unknown-field invariant.
455    pub(crate) fn mutation_structural_field_unknown(entity_path: &str, field_name: &str) -> Self {
456        Self::executor_invariant(format!(
457            "mutation field not found: {entity_path} field={field_name}",
458        ))
459    }
460
461    /// Construct an executor-origin save-preflight decimal-scale unsupported error.
462    pub(crate) fn mutation_decimal_scale_mismatch(
463        entity_path: &str,
464        field_name: &str,
465        expected_scale: impl fmt::Display,
466        actual_scale: impl fmt::Display,
467    ) -> Self {
468        Self::executor_unsupported(format!(
469            "decimal field scale mismatch: {entity_path} field={field_name} expected_scale={expected_scale} actual_scale={actual_scale}",
470        ))
471    }
472
473    /// Construct an executor-origin save-preflight text-length unsupported error.
474    pub(crate) fn mutation_text_max_len_exceeded(
475        entity_path: &str,
476        field_name: &str,
477        max_len: impl fmt::Display,
478        actual_len: impl fmt::Display,
479    ) -> Self {
480        Self::executor_unsupported(format!(
481            "text length exceeds max_len: {entity_path} field={field_name} max_len={max_len} actual_len={actual_len}",
482        ))
483    }
484
485    /// Construct an executor-origin save-preflight set-encoding invariant.
486    pub(crate) fn mutation_set_field_list_required(entity_path: &str, field_name: &str) -> Self {
487        Self::executor_invariant(format!(
488            "set field must encode as Value::List: {entity_path} field={field_name}",
489        ))
490    }
491
492    /// Construct an executor-origin save-preflight set-canonicality invariant.
493    pub(crate) fn mutation_set_field_not_canonical(entity_path: &str, field_name: &str) -> Self {
494        Self::executor_invariant(format!(
495            "set field must be strictly ordered and deduplicated: {entity_path} field={field_name}",
496        ))
497    }
498
499    /// Construct an executor-origin save-preflight map-encoding invariant.
500    pub(crate) fn mutation_map_field_map_required(entity_path: &str, field_name: &str) -> Self {
501        Self::executor_invariant(format!(
502            "map field must encode as Value::Map: {entity_path} field={field_name}",
503        ))
504    }
505
506    /// Construct an executor-origin save-preflight map-entry invariant.
507    pub(crate) fn mutation_map_field_entries_invalid(
508        entity_path: &str,
509        field_name: &str,
510        detail: impl fmt::Display,
511    ) -> Self {
512        Self::executor_invariant(format!(
513            "map field entries violate map invariants: {entity_path} field={field_name} ({detail})",
514        ))
515    }
516
517    /// Construct an executor-origin save-preflight map-canonicality invariant.
518    pub(crate) fn mutation_map_field_entries_not_canonical(
519        entity_path: &str,
520        field_name: &str,
521    ) -> Self {
522        Self::executor_invariant(format!(
523            "map field entries are not in canonical deterministic order: {entity_path} field={field_name}",
524        ))
525    }
526
527    /// Construct a query-origin scalar page invariant for ordering before filtering.
528    pub(crate) fn scalar_page_ordering_after_filtering_required() -> Self {
529        Self::query_executor_invariant("ordering must run after filtering")
530    }
531
532    /// Construct a query-origin scalar page invariant for missing order at the cursor boundary.
533    pub(crate) fn scalar_page_cursor_boundary_order_required() -> Self {
534        Self::query_executor_invariant("cursor boundary requires ordering")
535    }
536
537    /// Construct a query-origin scalar page invariant for cursor-before-ordering drift.
538    pub(crate) fn scalar_page_cursor_boundary_after_ordering_required() -> Self {
539        Self::query_executor_invariant("cursor boundary must run after ordering")
540    }
541
542    /// Construct a query-origin scalar page invariant for pagination-before-ordering drift.
543    pub(crate) fn scalar_page_pagination_after_ordering_required() -> Self {
544        Self::query_executor_invariant("pagination must run after ordering")
545    }
546
547    /// Construct a query-origin scalar page invariant for delete-limit-before-ordering drift.
548    pub(crate) fn scalar_page_delete_limit_after_ordering_required() -> Self {
549        Self::query_executor_invariant("delete limit must run after ordering")
550    }
551
552    /// Construct a query-origin load-runtime invariant for scalar-mode payload mismatch.
553    pub(crate) fn load_runtime_scalar_payload_required() -> Self {
554        Self::query_executor_invariant("scalar load mode must carry scalar runtime payload")
555    }
556
557    /// Construct a query-origin load-runtime invariant for grouped-mode payload mismatch.
558    pub(crate) fn load_runtime_grouped_payload_required() -> Self {
559        Self::query_executor_invariant("grouped load mode must carry grouped runtime payload")
560    }
561
562    /// Construct a query-origin load-surface invariant for scalar-page payload mismatch.
563    pub(crate) fn load_runtime_scalar_surface_payload_required() -> Self {
564        Self::query_executor_invariant("scalar page load mode must carry scalar runtime payload")
565    }
566
567    /// Construct a query-origin load-surface invariant for grouped-page payload mismatch.
568    pub(crate) fn load_runtime_grouped_surface_payload_required() -> Self {
569        Self::query_executor_invariant("grouped page load mode must carry grouped runtime payload")
570    }
571
572    /// Construct a query-origin load-entrypoint invariant for non-load plans.
573    pub(crate) fn load_executor_load_plan_required() -> Self {
574        Self::query_executor_invariant("load executor requires load plans")
575    }
576
577    /// Construct an executor-origin delete-entrypoint unsupported grouped-mode error.
578    pub(crate) fn delete_executor_grouped_unsupported() -> Self {
579        Self::executor_unsupported("grouped query execution is not yet enabled in this release")
580    }
581
582    /// Construct a query-origin delete-entrypoint invariant for non-delete plans.
583    pub(crate) fn delete_executor_delete_plan_required() -> Self {
584        Self::query_executor_invariant("delete executor requires delete plans")
585    }
586
587    /// Construct a query-origin aggregate kernel invariant for fold-mode contract drift.
588    pub(crate) fn aggregate_fold_mode_terminal_contract_required() -> Self {
589        Self::query_executor_invariant(
590            "aggregate fold mode must match route fold-mode contract for aggregate terminal",
591        )
592    }
593
594    /// Construct a query-origin fast-stream invariant for route kind/request mismatch.
595    pub(crate) fn fast_stream_route_kind_request_match_required() -> Self {
596        Self::query_executor_invariant("fast-stream route kind/request mismatch")
597    }
598
599    /// Construct a query-origin scan invariant for missing index-prefix executable specs.
600    pub(crate) fn secondary_index_prefix_spec_required() -> Self {
601        Self::query_executor_invariant(
602            "index-prefix executable spec must be materialized for index-prefix plans",
603        )
604    }
605
606    /// Construct a query-origin scan invariant for missing index-range executable specs.
607    pub(crate) fn index_range_limit_spec_required() -> Self {
608        Self::query_executor_invariant(
609            "index-range executable spec must be materialized for index-range plans",
610        )
611    }
612
613    /// Construct an executor-origin mutation unsupported error for duplicate atomic save keys.
614    pub(crate) fn mutation_atomic_save_duplicate_key(
615        entity_path: &str,
616        key: impl fmt::Display,
617    ) -> Self {
618        Self::executor_unsupported(format!(
619            "atomic save batch rejected duplicate key: entity={entity_path} key={key}",
620        ))
621    }
622
623    /// Construct an executor-origin mutation invariant for index-store generation drift.
624    pub(crate) fn mutation_index_store_generation_changed(
625        expected_generation: u64,
626        observed_generation: u64,
627    ) -> Self {
628        Self::executor_invariant(format!(
629            "index store generation changed between preflight and apply: expected {expected_generation}, found {observed_generation}",
630        ))
631    }
632
633    /// Build the canonical executor-invariant message prefix.
634    #[must_use]
635    #[cold]
636    #[inline(never)]
637    pub(crate) fn executor_invariant_message(reason: impl Into<String>) -> String {
638        format!("executor invariant violated: {}", reason.into())
639    }
640
641    /// Construct a planner-origin invariant violation.
642    #[cold]
643    #[inline(never)]
644    pub(crate) fn planner_invariant(message: impl Into<String>) -> Self {
645        Self::new(
646            ErrorClass::InvariantViolation,
647            ErrorOrigin::Planner,
648            message.into(),
649        )
650    }
651
652    /// Build the canonical invalid-logical-plan message prefix.
653    #[must_use]
654    pub(crate) fn invalid_logical_plan_message(reason: impl Into<String>) -> String {
655        format!("invalid logical plan: {}", reason.into())
656    }
657
658    /// Construct a planner-origin invariant with the canonical invalid-plan prefix.
659    pub(crate) fn query_invalid_logical_plan(reason: impl Into<String>) -> Self {
660        Self::planner_invariant(Self::invalid_logical_plan_message(reason))
661    }
662
663    /// Construct a store-origin invariant violation.
664    pub(crate) fn store_invariant(message: impl Into<String>) -> Self {
665        Self::new(
666            ErrorClass::InvariantViolation,
667            ErrorOrigin::Store,
668            message.into(),
669        )
670    }
671
672    /// Construct the canonical duplicate runtime-hook entity-tag invariant.
673    pub(crate) fn duplicate_runtime_hooks_for_entity_tag(
674        entity_tag: crate::types::EntityTag,
675    ) -> Self {
676        Self::store_invariant(format!(
677            "duplicate runtime hooks for entity tag '{}'",
678            entity_tag.value()
679        ))
680    }
681
682    /// Construct the canonical duplicate runtime-hook entity-path invariant.
683    pub(crate) fn duplicate_runtime_hooks_for_entity_path(entity_path: &str) -> Self {
684        Self::store_invariant(format!(
685            "duplicate runtime hooks for entity path '{entity_path}'"
686        ))
687    }
688
689    /// Construct a store-origin internal error.
690    #[cold]
691    #[inline(never)]
692    pub(crate) fn store_internal(message: impl Into<String>) -> Self {
693        Self::new(ErrorClass::Internal, ErrorOrigin::Store, message.into())
694    }
695
696    /// Construct the canonical unconfigured commit-memory id internal error.
697    pub(crate) fn commit_memory_id_unconfigured() -> Self {
698        Self::store_internal(
699            "commit memory id is not configured; initialize recovery before commit store access",
700        )
701    }
702
703    /// Construct the canonical commit-memory id mismatch internal error.
704    pub(crate) fn commit_memory_id_mismatch(cached_id: u8, configured_id: u8) -> Self {
705        Self::store_internal(format!(
706            "commit memory id mismatch: cached={cached_id}, configured={configured_id}",
707        ))
708    }
709
710    /// Construct the canonical commit-memory stable-key mismatch internal error.
711    pub(crate) fn commit_memory_stable_key_mismatch(
712        cached_key: &str,
713        configured_key: &str,
714    ) -> Self {
715        Self::store_internal(format!(
716            "commit memory stable key mismatch: cached={cached_key}, configured={configured_key}",
717        ))
718    }
719
720    /// Construct the canonical missing rollback-row invariant for delete execution.
721    pub(crate) fn delete_rollback_row_required() -> Self {
722        Self::store_internal("missing raw row for delete rollback")
723    }
724
725    /// Construct the canonical recovery-integrity totals corruption error.
726    pub(crate) fn recovery_integrity_validation_failed(
727        missing_index_entries: u64,
728        divergent_index_entries: u64,
729        orphan_index_references: u64,
730    ) -> Self {
731        Self::store_corruption(format!(
732            "recovery integrity validation failed: missing_index_entries={missing_index_entries} divergent_index_entries={divergent_index_entries} orphan_index_references={orphan_index_references}",
733        ))
734    }
735
736    /// Construct an index-origin internal error.
737    #[cold]
738    #[inline(never)]
739    pub(crate) fn index_internal(message: impl Into<String>) -> Self {
740        Self::new(ErrorClass::Internal, ErrorOrigin::Index, message.into())
741    }
742
743    /// Construct the canonical missing old entity-key internal error for structural index removal.
744    pub(crate) fn structural_index_removal_entity_key_required() -> Self {
745        Self::index_internal("missing old entity key for structural index removal")
746    }
747
748    /// Construct the canonical missing new entity-key internal error for structural index insertion.
749    pub(crate) fn structural_index_insertion_entity_key_required() -> Self {
750        Self::index_internal("missing new entity key for structural index insertion")
751    }
752
753    /// Construct the canonical missing old entity-key internal error for index commit-op removal.
754    pub(crate) fn index_commit_op_old_entity_key_required() -> Self {
755        Self::index_internal("missing old entity key for index removal")
756    }
757
758    /// Construct the canonical missing new entity-key internal error for index commit-op insertion.
759    pub(crate) fn index_commit_op_new_entity_key_required() -> Self {
760        Self::index_internal("missing new entity key for index insertion")
761    }
762
763    /// Construct a query-origin internal error.
764    #[cfg(test)]
765    pub(crate) fn query_internal(message: impl Into<String>) -> Self {
766        Self::new(ErrorClass::Internal, ErrorOrigin::Query, message.into())
767    }
768
769    /// Construct a query-origin unsupported error.
770    #[cold]
771    #[inline(never)]
772    pub(crate) fn query_unsupported(message: impl Into<String>) -> Self {
773        Self::new(ErrorClass::Unsupported, ErrorOrigin::Query, message.into())
774    }
775
776    /// Construct a query-origin SQL DDL admission error with structured detail.
777    #[cold]
778    #[inline(never)]
779    #[cfg(feature = "sql")]
780    pub(crate) fn query_schema_ddl_admission(
781        error: SchemaDdlAdmissionError,
782        message: impl Into<String>,
783    ) -> Self {
784        Self {
785            class: ErrorClass::Unsupported,
786            origin: ErrorOrigin::Query,
787            message: message.into(),
788            detail: Some(ErrorDetail::Query(QueryErrorDetail::SchemaDdlAdmission {
789                error,
790            })),
791        }
792    }
793
794    /// Construct a query-origin numeric overflow error with structured detail.
795    #[cold]
796    #[inline(never)]
797    pub(crate) fn query_numeric_overflow() -> Self {
798        Self {
799            class: ErrorClass::Unsupported,
800            origin: ErrorOrigin::Query,
801            message: "numeric overflow".to_string(),
802            detail: Some(ErrorDetail::Query(QueryErrorDetail::NumericOverflow)),
803        }
804    }
805
806    /// Construct a query-origin non-representable numeric result error with
807    /// structured detail.
808    #[cold]
809    #[inline(never)]
810    pub(crate) fn query_numeric_not_representable() -> Self {
811        Self {
812            class: ErrorClass::Unsupported,
813            origin: ErrorOrigin::Query,
814            message: "numeric result is not representable".to_string(),
815            detail: Some(ErrorDetail::Query(
816                QueryErrorDetail::NumericNotRepresentable,
817            )),
818        }
819    }
820
821    /// Construct a serialize-origin internal error.
822    #[cold]
823    #[inline(never)]
824    pub(crate) fn serialize_internal(message: impl Into<String>) -> Self {
825        Self::new(ErrorClass::Internal, ErrorOrigin::Serialize, message.into())
826    }
827
828    /// Construct the canonical persisted-row encode internal error.
829    pub(crate) fn persisted_row_encode_failed(detail: impl fmt::Display) -> Self {
830        Self::serialize_internal(format!("row encode failed: {detail}"))
831    }
832
833    /// Construct the canonical persisted-row field encode internal error.
834    pub(crate) fn persisted_row_field_encode_failed(
835        field_name: &str,
836        detail: impl fmt::Display,
837    ) -> Self {
838        Self::serialize_internal(format!(
839            "row encode failed for field '{field_name}': {detail}",
840        ))
841    }
842
843    /// Construct the canonical bytes(field) value encode internal error.
844    pub(crate) fn bytes_field_value_encode_failed(detail: impl fmt::Display) -> Self {
845        Self::serialize_internal(format!("bytes(field) value encode failed: {detail}"))
846    }
847
848    /// Construct a store-origin corruption error.
849    #[cold]
850    #[inline(never)]
851    pub(crate) fn store_corruption(message: impl Into<String>) -> Self {
852        Self::new(ErrorClass::Corruption, ErrorOrigin::Store, message.into())
853    }
854
855    /// Construct a store-origin commit-marker corruption error.
856    pub(crate) fn commit_corruption(detail: impl fmt::Display) -> Self {
857        Self::store_corruption(format!("commit marker corrupted: {detail}"))
858    }
859
860    /// Construct a store-origin commit-marker component corruption error.
861    pub(crate) fn commit_component_corruption(component: &str, detail: impl fmt::Display) -> Self {
862        Self::store_corruption(format!("commit marker {component} corrupted: {detail}"))
863    }
864
865    /// Construct the canonical commit-marker id generation internal error.
866    pub(crate) fn commit_id_generation_failed(detail: impl fmt::Display) -> Self {
867        Self::store_internal(format!("commit id generation failed: {detail}"))
868    }
869
870    /// Construct the canonical commit-marker payload u32-length-limit error.
871    pub(crate) fn commit_marker_payload_exceeds_u32_length_limit(label: &str, len: usize) -> Self {
872        Self::store_unsupported(format!("{label} exceeds u32 length limit: {len} bytes"))
873    }
874
875    /// Construct the canonical commit-marker component invalid-length corruption error.
876    pub(crate) fn commit_component_length_invalid(
877        component: &str,
878        len: usize,
879        expected: impl fmt::Display,
880    ) -> Self {
881        Self::commit_component_corruption(
882            component,
883            format!("invalid length {len}, expected {expected}"),
884        )
885    }
886
887    /// Construct the canonical commit-marker max-size corruption error.
888    pub(crate) fn commit_marker_exceeds_max_size(size: usize, max_size: u32) -> Self {
889        Self::commit_corruption(format!(
890            "commit marker exceeds max size: {size} bytes (limit {max_size})",
891        ))
892    }
893
894    /// Construct the canonical commit-control slot max-size unsupported error.
895    pub(crate) fn commit_control_slot_exceeds_max_size(size: usize, max_size: u32) -> Self {
896        Self::store_unsupported(format!(
897            "commit control slot exceeds max size: {size} bytes (limit {max_size})",
898        ))
899    }
900
901    /// Construct the canonical commit-control marker-bytes length-limit error.
902    pub(crate) fn commit_control_slot_marker_bytes_exceed_u32_length_limit(size: usize) -> Self {
903        Self::store_unsupported(format!(
904            "commit marker bytes exceed u32 length limit: {size} bytes",
905        ))
906    }
907
908    /// Construct the canonical startup index-rebuild invalid-data-key corruption error.
909    pub(crate) fn startup_index_rebuild_invalid_data_key(
910        store_path: &str,
911        detail: impl fmt::Display,
912    ) -> Self {
913        Self::store_corruption(format!(
914            "startup index rebuild failed: invalid data key in store '{store_path}' ({detail})",
915        ))
916    }
917
918    /// Construct an index-origin corruption error.
919    #[cold]
920    #[inline(never)]
921    pub(crate) fn index_corruption(message: impl Into<String>) -> Self {
922        Self::new(ErrorClass::Corruption, ErrorOrigin::Index, message.into())
923    }
924
925    /// Construct the canonical unique-validation corruption wrapper.
926    pub(crate) fn index_unique_validation_corruption(
927        entity_path: &str,
928        fields: &str,
929        detail: impl fmt::Display,
930    ) -> Self {
931        Self::index_plan_index_corruption(format!(
932            "index corrupted: {entity_path} ({fields}) -> {detail}",
933        ))
934    }
935
936    /// Construct the canonical structural index-entry corruption wrapper.
937    pub(crate) fn structural_index_entry_corruption(
938        entity_path: &str,
939        fields: &str,
940        detail: impl fmt::Display,
941    ) -> Self {
942        Self::index_plan_index_corruption(format!(
943            "index corrupted: {entity_path} ({fields}) -> {detail}",
944        ))
945    }
946
947    /// Construct the canonical missing new entity-key invariant during unique validation.
948    pub(crate) fn index_unique_validation_entity_key_required() -> Self {
949        Self::index_invariant("missing entity key during unique validation")
950    }
951
952    /// Construct the canonical unique-validation structural row-decode corruption error.
953    pub(crate) fn index_unique_validation_row_deserialize_failed(
954        data_key: impl fmt::Display,
955        source: impl fmt::Display,
956    ) -> Self {
957        Self::index_plan_serialize_corruption(format!(
958            "failed to structurally deserialize row: {data_key} ({source})"
959        ))
960    }
961
962    /// Construct the canonical unique-validation primary-key slot decode corruption error.
963    pub(crate) fn index_unique_validation_primary_key_decode_failed(
964        data_key: impl fmt::Display,
965        source: impl fmt::Display,
966    ) -> Self {
967        Self::index_plan_serialize_corruption(format!(
968            "failed to decode structural primary-key slot: {data_key} ({source})"
969        ))
970    }
971
972    /// Construct the canonical unique-validation stored key rebuild corruption error.
973    pub(crate) fn index_unique_validation_key_rebuild_failed(
974        data_key: impl fmt::Display,
975        entity_path: &str,
976        source: impl fmt::Display,
977    ) -> Self {
978        Self::index_plan_serialize_corruption(format!(
979            "failed to structurally decode unique key row {data_key} for {entity_path}: {source}",
980        ))
981    }
982
983    /// Construct the canonical unique-validation missing-row corruption error.
984    pub(crate) fn index_unique_validation_row_required(data_key: impl fmt::Display) -> Self {
985        Self::index_plan_store_corruption(format!("missing row: {data_key}"))
986    }
987
988    /// Construct the canonical index-only predicate missing-component invariant.
989    pub(crate) fn index_only_predicate_component_required() -> Self {
990        Self::index_invariant("index-only predicate program referenced missing index component")
991    }
992
993    /// Construct the canonical index-scan continuation-envelope invariant.
994    pub(crate) fn index_scan_continuation_anchor_within_envelope_required() -> Self {
995        Self::index_invariant(
996            "index-range continuation anchor is outside the requested range envelope",
997        )
998    }
999
1000    /// Construct the canonical index-scan continuation-advancement invariant.
1001    pub(crate) fn index_scan_continuation_advancement_required() -> Self {
1002        Self::index_invariant("index-range continuation scan did not advance beyond the anchor")
1003    }
1004
1005    /// Construct the canonical index-scan key-decode corruption error.
1006    pub(crate) fn index_scan_key_corrupted_during(
1007        context: &'static str,
1008        err: impl fmt::Display,
1009    ) -> Self {
1010        Self::index_corruption(format!("index key corrupted during {context}: {err}"))
1011    }
1012
1013    /// Construct the canonical index-scan missing projection-component invariant.
1014    pub(crate) fn index_projection_component_required(
1015        index_name: &str,
1016        component_index: usize,
1017    ) -> Self {
1018        Self::index_invariant(format!(
1019            "index projection referenced missing component: index='{index_name}' component_index={component_index}",
1020        ))
1021    }
1022
1023    /// Construct the canonical scan-time index-entry decode corruption error.
1024    pub(crate) fn index_entry_decode_failed(err: impl fmt::Display) -> Self {
1025        Self::index_corruption(err.to_string())
1026    }
1027
1028    /// Construct a serialize-origin corruption error.
1029    pub(crate) fn serialize_corruption(message: impl Into<String>) -> Self {
1030        Self::new(
1031            ErrorClass::Corruption,
1032            ErrorOrigin::Serialize,
1033            message.into(),
1034        )
1035    }
1036
1037    /// Construct the canonical persisted-row decode corruption error.
1038    pub(crate) fn persisted_row_decode_failed(detail: impl fmt::Display) -> Self {
1039        Self::serialize_corruption(format!("row decode: {detail}"))
1040    }
1041
1042    /// Construct the canonical persisted-row field decode corruption error.
1043    pub(crate) fn persisted_row_field_decode_failed(
1044        field_name: &str,
1045        detail: impl fmt::Display,
1046    ) -> Self {
1047        Self::serialize_corruption(format!(
1048            "row decode failed for field '{field_name}': {detail}",
1049        ))
1050    }
1051
1052    /// Construct the canonical persisted-row field-kind decode corruption error.
1053    pub(crate) fn persisted_row_field_kind_decode_failed(
1054        field_name: &str,
1055        field_kind: impl fmt::Debug,
1056        detail: impl fmt::Display,
1057    ) -> Self {
1058        Self::persisted_row_field_decode_failed(
1059            field_name,
1060            format!("kind={field_kind:?}: {detail}"),
1061        )
1062    }
1063
1064    /// Construct the canonical persisted-row scalar-payload length corruption error.
1065    pub(crate) fn persisted_row_field_payload_exact_len_required(
1066        field_name: &str,
1067        payload_kind: &str,
1068        expected_len: usize,
1069    ) -> Self {
1070        let unit = if expected_len == 1 { "byte" } else { "bytes" };
1071
1072        Self::persisted_row_field_decode_failed(
1073            field_name,
1074            format!("{payload_kind} payload must be exactly {expected_len} {unit}"),
1075        )
1076    }
1077
1078    /// Construct the canonical persisted-row scalar-payload empty-body corruption error.
1079    pub(crate) fn persisted_row_field_payload_must_be_empty(
1080        field_name: &str,
1081        payload_kind: &str,
1082    ) -> Self {
1083        Self::persisted_row_field_decode_failed(
1084            field_name,
1085            format!("{payload_kind} payload must be empty"),
1086        )
1087    }
1088
1089    /// Construct the canonical persisted-row scalar-payload invalid-byte corruption error.
1090    pub(crate) fn persisted_row_field_payload_invalid_byte(
1091        field_name: &str,
1092        payload_kind: &str,
1093        value: u8,
1094    ) -> Self {
1095        Self::persisted_row_field_decode_failed(
1096            field_name,
1097            format!("invalid {payload_kind} payload byte {value}"),
1098        )
1099    }
1100
1101    /// Construct the canonical persisted-row scalar-payload non-finite corruption error.
1102    pub(crate) fn persisted_row_field_payload_non_finite(
1103        field_name: &str,
1104        payload_kind: &str,
1105    ) -> Self {
1106        Self::persisted_row_field_decode_failed(
1107            field_name,
1108            format!("{payload_kind} payload is non-finite"),
1109        )
1110    }
1111
1112    /// Construct the canonical persisted-row scalar-payload out-of-range corruption error.
1113    pub(crate) fn persisted_row_field_payload_out_of_range(
1114        field_name: &str,
1115        payload_kind: &str,
1116    ) -> Self {
1117        Self::persisted_row_field_decode_failed(
1118            field_name,
1119            format!("{payload_kind} payload out of range for target type"),
1120        )
1121    }
1122
1123    /// Construct the canonical persisted-row invalid text payload corruption error.
1124    pub(crate) fn persisted_row_field_text_payload_invalid_utf8(
1125        field_name: &str,
1126        detail: impl fmt::Display,
1127    ) -> Self {
1128        Self::persisted_row_field_decode_failed(
1129            field_name,
1130            format!("invalid UTF-8 text payload ({detail})"),
1131        )
1132    }
1133
1134    /// Construct the canonical persisted-row structural slot-lookup invariant.
1135    pub(crate) fn persisted_row_slot_lookup_out_of_bounds(model_path: &str, slot: usize) -> Self {
1136        Self::index_invariant(format!(
1137            "slot lookup outside model bounds during structural row access: model='{model_path}' slot={slot}",
1138        ))
1139    }
1140
1141    /// Construct the canonical persisted-row structural slot-cache invariant.
1142    pub(crate) fn persisted_row_slot_cache_lookup_out_of_bounds(
1143        model_path: &str,
1144        slot: usize,
1145    ) -> Self {
1146        Self::index_invariant(format!(
1147            "slot cache lookup outside model bounds during structural row access: model='{model_path}' slot={slot}",
1148        ))
1149    }
1150
1151    /// Construct the canonical persisted-row primary-key decode corruption error.
1152    pub(crate) fn persisted_row_primary_key_not_primary_key_encodable(
1153        data_key: impl fmt::Debug,
1154        detail: impl fmt::Display,
1155    ) -> Self {
1156        Self::persisted_row_decode_failed(format!(
1157            "primary-key value is not primary-key encodable: {data_key:?} ({detail})",
1158        ))
1159    }
1160
1161    /// Construct the canonical persisted-row missing primary-key slot corruption error.
1162    pub(crate) fn persisted_row_primary_key_slot_missing(data_key: impl fmt::Debug) -> Self {
1163        Self::persisted_row_decode_failed(format!(
1164            "missing primary-key slot while validating {data_key:?}",
1165        ))
1166    }
1167
1168    /// Construct the canonical persisted-row key mismatch corruption error.
1169    pub(crate) fn persisted_row_key_mismatch(
1170        expected_key: impl fmt::Debug,
1171        found_key: impl fmt::Debug,
1172    ) -> Self {
1173        Self::store_corruption(format!(
1174            "row key mismatch: expected {expected_key:?}, found {found_key:?}",
1175        ))
1176    }
1177
1178    /// Construct the canonical persisted-row missing declared-field corruption error.
1179    pub(crate) fn persisted_row_declared_field_missing(field_name: &str) -> Self {
1180        Self::persisted_row_decode_failed(format!("missing declared field `{field_name}`"))
1181    }
1182
1183    /// Construct the canonical data-key entity mismatch corruption error.
1184    pub(crate) fn data_key_entity_mismatch(
1185        expected: impl fmt::Display,
1186        found: impl fmt::Display,
1187    ) -> Self {
1188        Self::store_corruption(format!(
1189            "data key entity mismatch: expected {expected}, found {found}",
1190        ))
1191    }
1192
1193    /// Construct the canonical reverse-index ordinal overflow internal error.
1194    pub(crate) fn reverse_index_ordinal_overflow(
1195        source_path: &str,
1196        field_name: &str,
1197        target_path: &str,
1198        detail: impl fmt::Display,
1199    ) -> Self {
1200        Self::index_internal(format!(
1201            "reverse index ordinal overflow: source={source_path} field={field_name} target={target_path} ({detail})",
1202        ))
1203    }
1204
1205    /// Construct the canonical reverse-index entry corruption error.
1206    pub(crate) fn reverse_index_entry_corrupted(
1207        source_path: &str,
1208        field_name: &str,
1209        target_path: &str,
1210        index_key: impl fmt::Debug,
1211        detail: impl fmt::Display,
1212    ) -> Self {
1213        Self::index_corruption(format!(
1214            "reverse index entry corrupted: source={source_path} field={field_name} target={target_path} key={index_key:?} ({detail})",
1215        ))
1216    }
1217
1218    /// Construct the canonical relation-target store missing internal error.
1219    pub(crate) fn relation_target_store_missing(
1220        source_path: &str,
1221        field_name: &str,
1222        target_path: &str,
1223        store_path: &str,
1224        detail: impl fmt::Display,
1225    ) -> Self {
1226        Self::executor_internal(format!(
1227            "relation target store missing: source={source_path} field={field_name} target={target_path} store={store_path} ({detail})",
1228        ))
1229    }
1230
1231    /// Construct the canonical relation-target key decode corruption error.
1232    pub(crate) fn relation_target_key_decode_failed(
1233        context_label: &str,
1234        source_path: &str,
1235        field_name: &str,
1236        target_path: &str,
1237        detail: impl fmt::Display,
1238    ) -> Self {
1239        Self::identity_corruption(format!(
1240            "{context_label}: source={source_path} field={field_name} target={target_path} ({detail})",
1241        ))
1242    }
1243
1244    /// Construct the canonical relation-target entity mismatch corruption error.
1245    pub(crate) fn relation_target_entity_mismatch(
1246        context_label: &str,
1247        source_path: &str,
1248        field_name: &str,
1249        target_path: &str,
1250        target_entity_name: &str,
1251        expected_tag: impl fmt::Display,
1252        actual_tag: impl fmt::Display,
1253    ) -> Self {
1254        Self::store_corruption(format!(
1255            "{context_label}: source={source_path} field={field_name} target={target_path} expected={target_entity_name} (tag={expected_tag}) actual_tag={actual_tag}",
1256        ))
1257    }
1258
1259    /// Construct the canonical relation-source row decode corruption error.
1260    pub(crate) fn relation_source_row_decode_failed(
1261        source_path: &str,
1262        field_name: &str,
1263        target_path: &str,
1264        detail: impl fmt::Display,
1265    ) -> Self {
1266        Self::serialize_corruption(format!(
1267            "relation source row decode: source={source_path} field={field_name} target={target_path} ({detail})",
1268        ))
1269    }
1270
1271    /// Construct the canonical relation-source unsupported scalar relation-key corruption error.
1272    pub(crate) fn relation_source_row_unsupported_scalar_relation_key(
1273        source_path: &str,
1274        field_name: &str,
1275        target_path: &str,
1276    ) -> Self {
1277        Self::serialize_corruption(format!(
1278            "relation source row decode: unsupported scalar relation key: source={source_path} field={field_name} target={target_path}",
1279        ))
1280    }
1281
1282    /// Construct the canonical unsupported strong-relation key-kind corruption error.
1283    pub(crate) fn relation_source_row_unsupported_key_kind(field_kind: impl fmt::Debug) -> Self {
1284        Self::serialize_corruption(format!(
1285            "unsupported strong relation key kind during structural decode: {field_kind:?}"
1286        ))
1287    }
1288
1289    /// Construct the canonical reverse-index relation-target decode invariant failure.
1290    pub(crate) fn reverse_index_relation_target_decode_invariant_violated(
1291        source_path: &str,
1292        field_name: &str,
1293        target_path: &str,
1294    ) -> Self {
1295        Self::executor_internal(format!(
1296            "relation target decode invariant violated while preparing reverse index: source={source_path} field={field_name} target={target_path}",
1297        ))
1298    }
1299
1300    /// Construct the canonical covering-component empty-payload corruption error.
1301    pub(crate) fn bytes_covering_component_payload_empty() -> Self {
1302        Self::index_corruption("index component payload is empty during covering projection decode")
1303    }
1304
1305    /// Construct the canonical covering-component truncated bool corruption error.
1306    pub(crate) fn bytes_covering_bool_payload_truncated() -> Self {
1307        Self::index_corruption("bool covering component payload is truncated")
1308    }
1309
1310    /// Construct the canonical covering-component invalid-length corruption error.
1311    pub(crate) fn bytes_covering_component_payload_invalid_length(payload_kind: &str) -> Self {
1312        Self::index_corruption(format!(
1313            "{payload_kind} covering component payload has invalid length"
1314        ))
1315    }
1316
1317    /// Construct the canonical covering-component invalid-bool corruption error.
1318    pub(crate) fn bytes_covering_bool_payload_invalid_value() -> Self {
1319        Self::index_corruption("bool covering component payload has invalid value")
1320    }
1321
1322    /// Construct the canonical covering-component invalid text terminator corruption error.
1323    pub(crate) fn bytes_covering_text_payload_invalid_terminator() -> Self {
1324        Self::index_corruption("text covering component payload has invalid terminator")
1325    }
1326
1327    /// Construct the canonical covering-component trailing-text corruption error.
1328    pub(crate) fn bytes_covering_text_payload_trailing_bytes() -> Self {
1329        Self::index_corruption("text covering component payload contains trailing bytes")
1330    }
1331
1332    /// Construct the canonical covering-component invalid-UTF-8 text corruption error.
1333    pub(crate) fn bytes_covering_text_payload_invalid_utf8() -> Self {
1334        Self::index_corruption("text covering component payload is not valid UTF-8")
1335    }
1336
1337    /// Construct the canonical covering-component invalid text escape corruption error.
1338    pub(crate) fn bytes_covering_text_payload_invalid_escape_byte() -> Self {
1339        Self::index_corruption("text covering component payload has invalid escape byte")
1340    }
1341
1342    /// Construct the canonical covering-component missing text terminator corruption error.
1343    pub(crate) fn bytes_covering_text_payload_missing_terminator() -> Self {
1344        Self::index_corruption("text covering component payload is missing terminator")
1345    }
1346
1347    /// Construct the canonical missing persisted-field decode error.
1348    #[must_use]
1349    pub fn missing_persisted_slot(field_name: &'static str) -> Self {
1350        Self::serialize_corruption(format!("row decode: missing required field '{field_name}'"))
1351    }
1352
1353    /// Construct an identity-origin corruption error.
1354    pub(crate) fn identity_corruption(message: impl Into<String>) -> Self {
1355        Self::new(
1356            ErrorClass::Corruption,
1357            ErrorOrigin::Identity,
1358            message.into(),
1359        )
1360    }
1361
1362    /// Construct a store-origin unsupported error.
1363    #[cold]
1364    #[inline(never)]
1365    pub(crate) fn store_unsupported(message: impl Into<String>) -> Self {
1366        Self::new(ErrorClass::Unsupported, ErrorOrigin::Store, message.into())
1367    }
1368
1369    /// Construct the canonical schema DDL publication race error.
1370    pub(crate) fn schema_ddl_publication_race_lost(entity_path: &'static str) -> Self {
1371        let message = format!(
1372            "SQL DDL publication race lost for entity '{entity_path}': accepted schema changed after DDL binding",
1373        );
1374
1375        Self {
1376            class: ErrorClass::Unsupported,
1377            origin: ErrorOrigin::Store,
1378            message,
1379            detail: Some(ErrorDetail::Store(
1380                StoreError::SchemaDdlPublicationRaceLost {
1381                    entity_path: entity_path.to_string(),
1382                },
1383            )),
1384        }
1385    }
1386
1387    /// Construct the canonical unsupported persisted entity-tag store error.
1388    pub(crate) fn unsupported_entity_tag_in_data_store(
1389        entity_tag: crate::types::EntityTag,
1390    ) -> Self {
1391        Self::store_unsupported(format!(
1392            "unsupported entity tag in data store: '{}'",
1393            entity_tag.value()
1394        ))
1395    }
1396
1397    /// Construct the canonical commit-memory id registration failure.
1398    #[cfg_attr(test, expect(dead_code))]
1399    pub(crate) fn commit_memory_id_registration_failed(err: impl fmt::Display) -> Self {
1400        Self::store_internal(format!("commit memory id registration failed: {err}"))
1401    }
1402
1403    /// Construct an index-origin unsupported error.
1404    pub(crate) fn index_unsupported(message: impl Into<String>) -> Self {
1405        Self::new(ErrorClass::Unsupported, ErrorOrigin::Index, message.into())
1406    }
1407
1408    /// Construct the canonical index-key component size-limit unsupported error.
1409    pub(crate) fn index_component_exceeds_max_size(
1410        key_item: impl fmt::Display,
1411        len: usize,
1412        max_component_size: usize,
1413    ) -> Self {
1414        Self::index_unsupported(format!(
1415            "index component exceeds max size: key item '{key_item}' -> {len} bytes (limit {max_component_size})",
1416        ))
1417    }
1418
1419    /// Construct a serialize-origin unsupported error.
1420    pub(crate) fn serialize_unsupported(message: impl Into<String>) -> Self {
1421        Self::new(
1422            ErrorClass::Unsupported,
1423            ErrorOrigin::Serialize,
1424            message.into(),
1425        )
1426    }
1427
1428    /// Construct a cursor-origin unsupported error.
1429    pub(crate) fn cursor_unsupported(message: impl Into<String>) -> Self {
1430        Self::new(ErrorClass::Unsupported, ErrorOrigin::Cursor, message.into())
1431    }
1432
1433    /// Construct a serialize-origin incompatible persisted-format error.
1434    pub(crate) fn serialize_incompatible_persisted_format(message: impl Into<String>) -> Self {
1435        Self::new(
1436            ErrorClass::IncompatiblePersistedFormat,
1437            ErrorOrigin::Serialize,
1438            message.into(),
1439        )
1440    }
1441
1442    /// Construct a query-origin unsupported error preserving one SQL parser
1443    /// unsupported-feature code in structured error detail.
1444    #[cfg(feature = "sql")]
1445    pub(crate) fn query_unsupported_sql_feature(feature: diagnostic_code::SqlFeatureCode) -> Self {
1446        let message = format!(
1447            "SQL query is not executable in this release: unsupported SQL feature: {feature:?}"
1448        );
1449
1450        Self {
1451            class: ErrorClass::Unsupported,
1452            origin: ErrorOrigin::Query,
1453            message,
1454            detail: Some(ErrorDetail::Query(
1455                QueryErrorDetail::UnsupportedSqlFeature { feature },
1456            )),
1457        }
1458    }
1459
1460    /// Construct a query-origin unsupported error preserving one SQL endpoint
1461    /// surface mismatch in structured error detail.
1462    #[cfg(feature = "sql")]
1463    pub(crate) fn query_sql_surface_mismatch(
1464        mismatch: diagnostic_code::SqlSurfaceMismatchCode,
1465        message: impl Into<String>,
1466    ) -> Self {
1467        Self {
1468            class: ErrorClass::Unsupported,
1469            origin: ErrorOrigin::Query,
1470            message: message.into(),
1471            detail: Some(ErrorDetail::Query(QueryErrorDetail::SqlSurfaceMismatch {
1472                mismatch,
1473            })),
1474        }
1475    }
1476
1477    pub fn store_not_found(key: impl Into<String>) -> Self {
1478        let key = key.into();
1479
1480        Self {
1481            class: ErrorClass::NotFound,
1482            origin: ErrorOrigin::Store,
1483            message: format!("data key not found: {key}"),
1484            detail: Some(ErrorDetail::Store(StoreError::NotFound { key })),
1485        }
1486    }
1487
1488    /// Construct a standardized unsupported-entity-path error.
1489    pub fn unsupported_entity_path(path: impl Into<String>) -> Self {
1490        let path = path.into();
1491
1492        Self::new(
1493            ErrorClass::Unsupported,
1494            ErrorOrigin::Store,
1495            format!("unsupported entity path: '{path}'"),
1496        )
1497    }
1498
1499    #[must_use]
1500    pub const fn is_not_found(&self) -> bool {
1501        matches!(
1502            self.detail,
1503            Some(ErrorDetail::Store(StoreError::NotFound { .. }))
1504        )
1505    }
1506
1507    #[must_use]
1508    pub fn display_with_class(&self) -> String {
1509        format!("{}:{}: {}", self.origin, self.class, self.message)
1510    }
1511
1512    /// Construct an index-plan corruption error with a canonical prefix.
1513    #[cold]
1514    #[inline(never)]
1515    pub(crate) fn index_plan_corruption(origin: ErrorOrigin, message: impl Into<String>) -> Self {
1516        let message = message.into();
1517        Self::new(
1518            ErrorClass::Corruption,
1519            origin,
1520            format!("corruption detected ({origin}): {message}"),
1521        )
1522    }
1523
1524    /// Construct an index-plan corruption error for index-origin failures.
1525    #[cold]
1526    #[inline(never)]
1527    pub(crate) fn index_plan_index_corruption(message: impl Into<String>) -> Self {
1528        Self::index_plan_corruption(ErrorOrigin::Index, message)
1529    }
1530
1531    /// Construct an index-plan corruption error for store-origin failures.
1532    #[cold]
1533    #[inline(never)]
1534    pub(crate) fn index_plan_store_corruption(message: impl Into<String>) -> Self {
1535        Self::index_plan_corruption(ErrorOrigin::Store, message)
1536    }
1537
1538    /// Construct an index-plan corruption error for serialize-origin failures.
1539    #[cold]
1540    #[inline(never)]
1541    pub(crate) fn index_plan_serialize_corruption(message: impl Into<String>) -> Self {
1542        Self::index_plan_corruption(ErrorOrigin::Serialize, message)
1543    }
1544
1545    /// Construct an index-plan invariant violation error with a canonical prefix.
1546    #[cfg(test)]
1547    pub(crate) fn index_plan_invariant(origin: ErrorOrigin, message: impl Into<String>) -> Self {
1548        let message = message.into();
1549        Self::new(
1550            ErrorClass::InvariantViolation,
1551            origin,
1552            format!("invariant violation detected ({origin}): {message}"),
1553        )
1554    }
1555
1556    /// Construct an index-plan invariant violation error for store-origin failures.
1557    #[cfg(test)]
1558    pub(crate) fn index_plan_store_invariant(message: impl Into<String>) -> Self {
1559        Self::index_plan_invariant(ErrorOrigin::Store, message)
1560    }
1561
1562    /// Construct an index uniqueness violation conflict error.
1563    pub(crate) fn index_violation(path: &str, index_fields: &[&str]) -> Self {
1564        Self::new(
1565            ErrorClass::Conflict,
1566            ErrorOrigin::Index,
1567            format!(
1568                "index constraint violation: {path} ({})",
1569                index_fields.join(", ")
1570            ),
1571        )
1572    }
1573}
1574
1575///
1576/// ErrorDetail
1577///
1578/// Structured, origin-specific error detail carried by [`InternalError`].
1579/// This enum is intentionally extensible.
1580///
1581
1582#[derive(Debug, ThisError)]
1583pub enum ErrorDetail {
1584    #[error("{0}")]
1585    Store(StoreError),
1586    #[error("{0}")]
1587    Query(QueryErrorDetail),
1588    // Future-proofing:
1589    // #[error("{0}")]
1590    // Index(IndexError),
1591    //
1592    // #[error("{0}")]
1593    // Executor(ExecutorErrorDetail),
1594}
1595
1596///
1597/// StoreError
1598///
1599/// Store-specific structured error detail.
1600/// Never returned directly; always wrapped in [`ErrorDetail::Store`].
1601///
1602
1603#[derive(Debug, ThisError)]
1604pub enum StoreError {
1605    #[error("key not found: {key}")]
1606    NotFound { key: String },
1607
1608    #[error("store corruption: {message}")]
1609    Corrupt { message: String },
1610
1611    #[error("store invariant violation: {message}")]
1612    InvariantViolation { message: String },
1613
1614    #[error("schema DDL publication race lost for entity: {entity_path}")]
1615    SchemaDdlPublicationRaceLost { entity_path: String },
1616}
1617
1618///
1619/// QueryErrorDetail
1620///
1621/// Query-origin structured error detail payload.
1622///
1623
1624#[derive(Debug, ThisError)]
1625pub enum QueryErrorDetail {
1626    #[error("numeric overflow")]
1627    NumericOverflow,
1628
1629    #[error("numeric result is not representable")]
1630    NumericNotRepresentable,
1631
1632    #[error("unsupported SQL feature: {feature:?}")]
1633    UnsupportedSqlFeature {
1634        feature: diagnostic_code::SqlFeatureCode,
1635    },
1636
1637    #[error("SQL endpoint surface mismatch: {mismatch:?}")]
1638    SqlSurfaceMismatch {
1639        mismatch: diagnostic_code::SqlSurfaceMismatchCode,
1640    },
1641
1642    #[error("SQL DDL admission rejected: {error}")]
1643    SchemaDdlAdmission { error: SchemaDdlAdmissionError },
1644}
1645
1646///
1647/// SchemaDdlAdmissionError
1648///
1649/// Stable query-visible SQL DDL admission reason. Human diagnostics may carry
1650/// extra version, fingerprint, and target facts beside this machine-readable
1651/// variant.
1652///
1653
1654#[derive(Clone, Copy, Debug, Eq, PartialEq, ThisError)]
1655pub enum SchemaDdlAdmissionError {
1656    #[error("missing expected schema version")]
1657    MissingExpectedSchemaVersion,
1658
1659    #[error("missing next schema version")]
1660    MissingNextSchemaVersion,
1661
1662    #[error("stale expected schema version")]
1663    StaleExpectedSchemaVersion,
1664
1665    #[error("invalid expected schema version")]
1666    InvalidExpectedSchemaVersion,
1667
1668    #[error("invalid next schema version")]
1669    InvalidNextSchemaVersion,
1670
1671    #[error("accepted schema changed without version bump")]
1672    AcceptedSchemaChangeWithoutVersionBump,
1673
1674    #[error("empty version bump")]
1675    EmptyVersionBump,
1676
1677    #[error("version gap")]
1678    VersionGap,
1679
1680    #[error("version rollback")]
1681    VersionRollback,
1682
1683    #[error("fingerprint method mismatch")]
1684    FingerprintMethodMismatch,
1685
1686    #[error("unsupported transition class")]
1687    UnsupportedTransitionClass,
1688
1689    #[error("physical runner missing")]
1690    PhysicalRunnerMissing,
1691
1692    #[error("validation failed")]
1693    ValidationFailed,
1694
1695    #[error("publication race lost")]
1696    PublicationRaceLost,
1697}
1698
1699impl ErrorDetail {
1700    /// Return the compact diagnostic code for this structured detail.
1701    #[must_use]
1702    pub const fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
1703        match self {
1704            Self::Store(error) => error.diagnostic_code(),
1705            Self::Query(error) => error.diagnostic_code(),
1706        }
1707    }
1708
1709    /// Return compact structured diagnostic detail when the payload carries one.
1710    #[must_use]
1711    pub const fn diagnostic_detail(&self) -> Option<diagnostic_code::DiagnosticDetail> {
1712        match self {
1713            Self::Store(error) => error.diagnostic_detail(),
1714            Self::Query(error) => error.diagnostic_detail(),
1715        }
1716    }
1717}
1718
1719impl StoreError {
1720    /// Return the compact diagnostic code for this store detail.
1721    #[must_use]
1722    pub const fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
1723        match self {
1724            Self::NotFound { .. } => diagnostic_code::DiagnosticCode::StoreNotFound,
1725            Self::Corrupt { .. } => diagnostic_code::DiagnosticCode::StoreCorruption,
1726            Self::InvariantViolation { .. } => {
1727                diagnostic_code::DiagnosticCode::StoreInvariantViolation
1728            }
1729            Self::SchemaDdlPublicationRaceLost { .. } => {
1730                diagnostic_code::DiagnosticCode::SchemaDdlAdmission
1731            }
1732        }
1733    }
1734
1735    /// Return compact structured diagnostic detail when the store error has one.
1736    #[must_use]
1737    pub const fn diagnostic_detail(&self) -> Option<diagnostic_code::DiagnosticDetail> {
1738        match self {
1739            Self::SchemaDdlPublicationRaceLost { .. } => {
1740                Some(diagnostic_code::DiagnosticDetail::SchemaDdlAdmission {
1741                    reason: diagnostic_code::SchemaDdlAdmissionCode::PublicationRaceLost,
1742                })
1743            }
1744            Self::NotFound { .. } | Self::Corrupt { .. } | Self::InvariantViolation { .. } => None,
1745        }
1746    }
1747}
1748
1749impl QueryErrorDetail {
1750    /// Return the compact diagnostic code for this query detail.
1751    #[must_use]
1752    pub const fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
1753        match self {
1754            Self::NumericOverflow => diagnostic_code::DiagnosticCode::QueryNumericOverflow,
1755            Self::NumericNotRepresentable => {
1756                diagnostic_code::DiagnosticCode::QueryNumericNotRepresentable
1757            }
1758            Self::UnsupportedSqlFeature { .. } => {
1759                diagnostic_code::DiagnosticCode::QueryUnsupportedSqlFeature
1760            }
1761            Self::SqlSurfaceMismatch { .. } => {
1762                diagnostic_code::DiagnosticCode::QuerySqlSurfaceMismatch
1763            }
1764            Self::SchemaDdlAdmission { .. } => diagnostic_code::DiagnosticCode::SchemaDdlAdmission,
1765        }
1766    }
1767
1768    /// Return compact structured diagnostic detail when the query detail has one.
1769    #[must_use]
1770    pub const fn diagnostic_detail(&self) -> Option<diagnostic_code::DiagnosticDetail> {
1771        match self {
1772            Self::UnsupportedSqlFeature { feature } => {
1773                Some(diagnostic_code::DiagnosticDetail::UnsupportedSqlFeature { feature: *feature })
1774            }
1775            Self::SqlSurfaceMismatch { mismatch } => {
1776                Some(diagnostic_code::DiagnosticDetail::SqlSurfaceMismatch {
1777                    mismatch: *mismatch,
1778                })
1779            }
1780            Self::SchemaDdlAdmission { error } => {
1781                Some(diagnostic_code::DiagnosticDetail::SchemaDdlAdmission {
1782                    reason: error.diagnostic_code(),
1783                })
1784            }
1785            Self::NumericOverflow | Self::NumericNotRepresentable => None,
1786        }
1787    }
1788}
1789
1790impl SchemaDdlAdmissionError {
1791    /// Return the compact diagnostic code for this SQL DDL admission reason.
1792    #[must_use]
1793    pub const fn diagnostic_code(&self) -> diagnostic_code::SchemaDdlAdmissionCode {
1794        match self {
1795            Self::MissingExpectedSchemaVersion => {
1796                diagnostic_code::SchemaDdlAdmissionCode::MissingExpectedSchemaVersion
1797            }
1798            Self::MissingNextSchemaVersion => {
1799                diagnostic_code::SchemaDdlAdmissionCode::MissingNextSchemaVersion
1800            }
1801            Self::StaleExpectedSchemaVersion => {
1802                diagnostic_code::SchemaDdlAdmissionCode::StaleExpectedSchemaVersion
1803            }
1804            Self::InvalidExpectedSchemaVersion => {
1805                diagnostic_code::SchemaDdlAdmissionCode::InvalidExpectedSchemaVersion
1806            }
1807            Self::InvalidNextSchemaVersion => {
1808                diagnostic_code::SchemaDdlAdmissionCode::InvalidNextSchemaVersion
1809            }
1810            Self::AcceptedSchemaChangeWithoutVersionBump => {
1811                diagnostic_code::SchemaDdlAdmissionCode::AcceptedSchemaChangeWithoutVersionBump
1812            }
1813            Self::EmptyVersionBump => diagnostic_code::SchemaDdlAdmissionCode::EmptyVersionBump,
1814            Self::VersionGap => diagnostic_code::SchemaDdlAdmissionCode::VersionGap,
1815            Self::VersionRollback => diagnostic_code::SchemaDdlAdmissionCode::VersionRollback,
1816            Self::FingerprintMethodMismatch => {
1817                diagnostic_code::SchemaDdlAdmissionCode::FingerprintMethodMismatch
1818            }
1819            Self::UnsupportedTransitionClass => {
1820                diagnostic_code::SchemaDdlAdmissionCode::UnsupportedTransitionClass
1821            }
1822            Self::PhysicalRunnerMissing => {
1823                diagnostic_code::SchemaDdlAdmissionCode::PhysicalRunnerMissing
1824            }
1825            Self::ValidationFailed => diagnostic_code::SchemaDdlAdmissionCode::ValidationFailed,
1826            Self::PublicationRaceLost => {
1827                diagnostic_code::SchemaDdlAdmissionCode::PublicationRaceLost
1828            }
1829        }
1830    }
1831}
1832
1833///
1834/// ErrorClass
1835/// Internal error taxonomy for runtime classification.
1836/// Not a stable API; may change without notice.
1837///
1838
1839#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1840pub enum ErrorClass {
1841    Corruption,
1842    IncompatiblePersistedFormat,
1843    NotFound,
1844    Internal,
1845    Conflict,
1846    Unsupported,
1847    InvariantViolation,
1848}
1849
1850impl ErrorClass {
1851    /// Return a compact diagnostic code for this broad class and origin pair.
1852    #[must_use]
1853    pub const fn diagnostic_code(self, origin: ErrorOrigin) -> diagnostic_code::DiagnosticCode {
1854        match self {
1855            Self::Corruption if matches!(origin, ErrorOrigin::Store) => {
1856                diagnostic_code::DiagnosticCode::StoreCorruption
1857            }
1858            Self::Corruption => diagnostic_code::DiagnosticCode::RuntimeCorruption,
1859            Self::IncompatiblePersistedFormat => {
1860                diagnostic_code::DiagnosticCode::RuntimeIncompatiblePersistedFormat
1861            }
1862            Self::NotFound if matches!(origin, ErrorOrigin::Store) => {
1863                diagnostic_code::DiagnosticCode::StoreNotFound
1864            }
1865            Self::NotFound => diagnostic_code::DiagnosticCode::RuntimeNotFound,
1866            Self::Internal => diagnostic_code::DiagnosticCode::RuntimeInternal,
1867            Self::Conflict => diagnostic_code::DiagnosticCode::RuntimeConflict,
1868            Self::Unsupported => diagnostic_code::DiagnosticCode::RuntimeUnsupported,
1869            Self::InvariantViolation if matches!(origin, ErrorOrigin::Store) => {
1870                diagnostic_code::DiagnosticCode::StoreInvariantViolation
1871            }
1872            Self::InvariantViolation => diagnostic_code::DiagnosticCode::RuntimeInvariantViolation,
1873        }
1874    }
1875}
1876
1877impl fmt::Display for ErrorClass {
1878    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1879        let label = match self {
1880            Self::Corruption => "corruption",
1881            Self::IncompatiblePersistedFormat => "incompatible_persisted_format",
1882            Self::NotFound => "not_found",
1883            Self::Internal => "internal",
1884            Self::Conflict => "conflict",
1885            Self::Unsupported => "unsupported",
1886            Self::InvariantViolation => "invariant_violation",
1887        };
1888        write!(f, "{label}")
1889    }
1890}
1891
1892///
1893/// ErrorOrigin
1894/// Internal origin taxonomy for runtime classification.
1895/// Not a stable API; may change without notice.
1896///
1897
1898#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1899pub enum ErrorOrigin {
1900    Serialize,
1901    Store,
1902    Index,
1903    Identity,
1904    Query,
1905    Planner,
1906    Cursor,
1907    Recovery,
1908    Response,
1909    Executor,
1910    Interface,
1911}
1912
1913impl ErrorOrigin {
1914    /// Return the compact diagnostic origin for this internal origin.
1915    #[must_use]
1916    pub const fn diagnostic_origin(self) -> diagnostic_code::ErrorOrigin {
1917        match self {
1918            Self::Serialize => diagnostic_code::ErrorOrigin::Serialize,
1919            Self::Store => diagnostic_code::ErrorOrigin::Store,
1920            Self::Index => diagnostic_code::ErrorOrigin::Index,
1921            Self::Identity => diagnostic_code::ErrorOrigin::Identity,
1922            Self::Query => diagnostic_code::ErrorOrigin::Query,
1923            Self::Planner => diagnostic_code::ErrorOrigin::Planner,
1924            Self::Cursor => diagnostic_code::ErrorOrigin::Cursor,
1925            Self::Recovery => diagnostic_code::ErrorOrigin::Recovery,
1926            Self::Response => diagnostic_code::ErrorOrigin::Response,
1927            Self::Executor => diagnostic_code::ErrorOrigin::Executor,
1928            Self::Interface => diagnostic_code::ErrorOrigin::Interface,
1929        }
1930    }
1931}
1932
1933impl fmt::Display for ErrorOrigin {
1934    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1935        let label = match self {
1936            Self::Serialize => "serialize",
1937            Self::Store => "store",
1938            Self::Index => "index",
1939            Self::Identity => "identity",
1940            Self::Query => "query",
1941            Self::Planner => "planner",
1942            Self::Cursor => "cursor",
1943            Self::Recovery => "recovery",
1944            Self::Response => "response",
1945            Self::Executor => "executor",
1946            Self::Interface => "interface",
1947        };
1948        write!(f, "{label}")
1949    }
1950}