1#[cfg(test)]
8mod tests;
9
10use crate::serialize::{SerializeError, SerializeErrorKind};
11use std::fmt;
12use thiserror::Error as ThisError;
13
14#[derive(Debug, ThisError)]
115#[error("{message}")]
116pub struct InternalError {
117 pub(crate) class: ErrorClass,
118 pub(crate) origin: ErrorOrigin,
119 pub(crate) message: String,
120
121 pub(crate) detail: Option<ErrorDetail>,
124}
125
126impl InternalError {
127 #[cold]
131 #[inline(never)]
132 pub fn new(class: ErrorClass, origin: ErrorOrigin, message: impl Into<String>) -> Self {
133 let message = message.into();
134
135 let detail = match (class, origin) {
136 (ErrorClass::Corruption, ErrorOrigin::Store) => {
137 Some(ErrorDetail::Store(StoreError::Corrupt {
138 message: message.clone(),
139 }))
140 }
141 (ErrorClass::InvariantViolation, ErrorOrigin::Store) => {
142 Some(ErrorDetail::Store(StoreError::InvariantViolation {
143 message: message.clone(),
144 }))
145 }
146 _ => None,
147 };
148
149 Self {
150 class,
151 origin,
152 message,
153 detail,
154 }
155 }
156
157 #[must_use]
159 pub const fn class(&self) -> ErrorClass {
160 self.class
161 }
162
163 #[must_use]
165 pub const fn origin(&self) -> ErrorOrigin {
166 self.origin
167 }
168
169 #[must_use]
171 pub fn message(&self) -> &str {
172 &self.message
173 }
174
175 #[must_use]
177 pub const fn detail(&self) -> Option<&ErrorDetail> {
178 self.detail.as_ref()
179 }
180
181 #[must_use]
183 pub fn into_message(self) -> String {
184 self.message
185 }
186
187 #[cold]
189 #[inline(never)]
190 pub(crate) fn classified(
191 class: ErrorClass,
192 origin: ErrorOrigin,
193 message: impl Into<String>,
194 ) -> Self {
195 Self::new(class, origin, message)
196 }
197
198 #[cold]
200 #[inline(never)]
201 pub(crate) fn with_message(self, message: impl Into<String>) -> Self {
202 Self::classified(self.class, self.origin, message)
203 }
204
205 #[cold]
209 #[inline(never)]
210 pub(crate) fn with_origin(self, origin: ErrorOrigin) -> Self {
211 Self::classified(self.class, origin, self.message)
212 }
213
214 #[cold]
216 #[inline(never)]
217 pub(crate) fn index_invariant(message: impl Into<String>) -> Self {
218 Self::new(
219 ErrorClass::InvariantViolation,
220 ErrorOrigin::Index,
221 message.into(),
222 )
223 }
224
225 pub(crate) fn index_key_field_count_exceeds_max(
227 index_name: &str,
228 field_count: usize,
229 max_fields: usize,
230 ) -> Self {
231 Self::index_invariant(format!(
232 "index '{index_name}' has {field_count} fields (max {max_fields})",
233 ))
234 }
235
236 pub(crate) fn index_key_item_field_missing_on_entity_model(field: &str) -> Self {
238 Self::index_invariant(format!(
239 "index key item field missing on entity model: {field}",
240 ))
241 }
242
243 pub(crate) fn index_key_item_field_missing_on_lookup_row(field: &str) -> Self {
245 Self::index_invariant(format!(
246 "index key item field missing on lookup row: {field}",
247 ))
248 }
249
250 pub(crate) fn index_expression_source_type_mismatch(
252 index_name: &str,
253 expression: impl fmt::Display,
254 expected: &str,
255 source_label: &str,
256 ) -> Self {
257 Self::index_invariant(format!(
258 "index '{index_name}' expression '{expression}' expected {expected} source value, got {source_label}",
259 ))
260 }
261
262 #[cold]
265 #[inline(never)]
266 pub(crate) fn planner_executor_invariant(reason: impl Into<String>) -> Self {
267 Self::new(
268 ErrorClass::InvariantViolation,
269 ErrorOrigin::Planner,
270 Self::executor_invariant_message(reason),
271 )
272 }
273
274 #[cold]
277 #[inline(never)]
278 pub(crate) fn query_executor_invariant(reason: impl Into<String>) -> Self {
279 Self::new(
280 ErrorClass::InvariantViolation,
281 ErrorOrigin::Query,
282 Self::executor_invariant_message(reason),
283 )
284 }
285
286 #[cold]
289 #[inline(never)]
290 pub(crate) fn cursor_executor_invariant(reason: impl Into<String>) -> Self {
291 Self::new(
292 ErrorClass::InvariantViolation,
293 ErrorOrigin::Cursor,
294 Self::executor_invariant_message(reason),
295 )
296 }
297
298 #[cold]
300 #[inline(never)]
301 pub(crate) fn executor_invariant(message: impl Into<String>) -> Self {
302 Self::new(
303 ErrorClass::InvariantViolation,
304 ErrorOrigin::Executor,
305 message.into(),
306 )
307 }
308
309 #[cold]
311 #[inline(never)]
312 pub(crate) fn executor_internal(message: impl Into<String>) -> Self {
313 Self::new(ErrorClass::Internal, ErrorOrigin::Executor, message.into())
314 }
315
316 #[cold]
318 #[inline(never)]
319 pub(crate) fn executor_unsupported(message: impl Into<String>) -> Self {
320 Self::new(
321 ErrorClass::Unsupported,
322 ErrorOrigin::Executor,
323 message.into(),
324 )
325 }
326
327 pub(crate) fn mutation_entity_primary_key_missing(entity_path: &str, field_name: &str) -> Self {
329 Self::executor_invariant(format!(
330 "entity primary key field missing: {entity_path} field={field_name}",
331 ))
332 }
333
334 pub(crate) fn mutation_entity_primary_key_invalid_value(
336 entity_path: &str,
337 field_name: &str,
338 value: &crate::value::Value,
339 ) -> Self {
340 Self::executor_invariant(format!(
341 "entity primary key field has invalid value: {entity_path} field={field_name} value={value:?}",
342 ))
343 }
344
345 pub(crate) fn mutation_entity_primary_key_type_mismatch(
347 entity_path: &str,
348 field_name: &str,
349 value: &crate::value::Value,
350 ) -> Self {
351 Self::executor_invariant(format!(
352 "entity primary key field type mismatch: {entity_path} field={field_name} value={value:?}",
353 ))
354 }
355
356 pub(crate) fn mutation_entity_primary_key_mismatch(
358 entity_path: &str,
359 field_name: &str,
360 field_value: &crate::value::Value,
361 identity_key: &crate::value::Value,
362 ) -> Self {
363 Self::executor_invariant(format!(
364 "entity primary key mismatch: {entity_path} field={field_name} field_value={field_value:?} id_key={identity_key:?}",
365 ))
366 }
367
368 pub(crate) fn mutation_entity_field_missing(
370 entity_path: &str,
371 field_name: &str,
372 indexed: bool,
373 ) -> Self {
374 let indexed_note = if indexed { " (indexed)" } else { "" };
375
376 Self::executor_invariant(format!(
377 "entity field missing: {entity_path} field={field_name}{indexed_note}",
378 ))
379 }
380
381 pub(crate) fn mutation_entity_field_type_mismatch(
383 entity_path: &str,
384 field_name: &str,
385 value: &crate::value::Value,
386 ) -> Self {
387 Self::executor_invariant(format!(
388 "entity field type mismatch: {entity_path} field={field_name} value={value:?}",
389 ))
390 }
391
392 pub(crate) fn mutation_structural_after_image_invalid(
397 entity_path: &str,
398 data_key: impl fmt::Display,
399 detail: impl AsRef<str>,
400 ) -> Self {
401 Self::executor_invariant(format!(
402 "mutation result is invalid: {entity_path} key={data_key} ({})",
403 detail.as_ref(),
404 ))
405 }
406
407 pub(crate) fn mutation_structural_field_unknown(entity_path: &str, field_name: &str) -> Self {
409 Self::executor_invariant(format!(
410 "mutation field not found: {entity_path} field={field_name}",
411 ))
412 }
413
414 pub(crate) fn mutation_decimal_scale_mismatch(
416 entity_path: &str,
417 field_name: &str,
418 expected_scale: impl fmt::Display,
419 actual_scale: impl fmt::Display,
420 ) -> Self {
421 Self::executor_unsupported(format!(
422 "decimal field scale mismatch: {entity_path} field={field_name} expected_scale={expected_scale} actual_scale={actual_scale}",
423 ))
424 }
425
426 pub(crate) fn mutation_set_field_list_required(entity_path: &str, field_name: &str) -> Self {
428 Self::executor_invariant(format!(
429 "set field must encode as Value::List: {entity_path} field={field_name}",
430 ))
431 }
432
433 pub(crate) fn mutation_set_field_not_canonical(entity_path: &str, field_name: &str) -> Self {
435 Self::executor_invariant(format!(
436 "set field must be strictly ordered and deduplicated: {entity_path} field={field_name}",
437 ))
438 }
439
440 pub(crate) fn mutation_map_field_map_required(entity_path: &str, field_name: &str) -> Self {
442 Self::executor_invariant(format!(
443 "map field must encode as Value::Map: {entity_path} field={field_name}",
444 ))
445 }
446
447 pub(crate) fn mutation_map_field_entries_invalid(
449 entity_path: &str,
450 field_name: &str,
451 detail: impl fmt::Display,
452 ) -> Self {
453 Self::executor_invariant(format!(
454 "map field entries violate map invariants: {entity_path} field={field_name} ({detail})",
455 ))
456 }
457
458 pub(crate) fn mutation_map_field_entries_not_canonical(
460 entity_path: &str,
461 field_name: &str,
462 ) -> Self {
463 Self::executor_invariant(format!(
464 "map field entries are not in canonical deterministic order: {entity_path} field={field_name}",
465 ))
466 }
467
468 pub(crate) fn scalar_page_predicate_slots_required() -> Self {
470 Self::query_executor_invariant("post-access filtering requires precompiled predicate slots")
471 }
472
473 pub(crate) fn scalar_page_ordering_after_filtering_required() -> Self {
475 Self::query_executor_invariant("ordering must run after filtering")
476 }
477
478 pub(crate) fn scalar_page_cursor_boundary_order_required() -> Self {
480 Self::query_executor_invariant("cursor boundary requires ordering")
481 }
482
483 pub(crate) fn scalar_page_cursor_boundary_after_ordering_required() -> Self {
485 Self::query_executor_invariant("cursor boundary must run after ordering")
486 }
487
488 pub(crate) fn scalar_page_pagination_after_ordering_required() -> Self {
490 Self::query_executor_invariant("pagination must run after ordering")
491 }
492
493 pub(crate) fn scalar_page_delete_limit_after_ordering_required() -> Self {
495 Self::query_executor_invariant("delete limit must run after ordering")
496 }
497
498 pub(crate) fn load_runtime_scalar_payload_required() -> Self {
500 Self::query_executor_invariant("scalar load mode must carry scalar runtime payload")
501 }
502
503 pub(crate) fn load_runtime_grouped_payload_required() -> Self {
505 Self::query_executor_invariant("grouped load mode must carry grouped runtime payload")
506 }
507
508 pub(crate) fn load_runtime_scalar_surface_payload_required() -> Self {
510 Self::query_executor_invariant("scalar page load mode must carry scalar runtime payload")
511 }
512
513 pub(crate) fn load_runtime_grouped_surface_payload_required() -> Self {
515 Self::query_executor_invariant("grouped page load mode must carry grouped runtime payload")
516 }
517
518 pub(crate) fn load_executor_load_plan_required() -> Self {
520 Self::query_executor_invariant("load executor requires load plans")
521 }
522
523 pub(crate) fn delete_executor_grouped_unsupported() -> Self {
525 Self::executor_unsupported("grouped query execution is not yet enabled in this release")
526 }
527
528 pub(crate) fn delete_executor_delete_plan_required() -> Self {
530 Self::query_executor_invariant("delete executor requires delete plans")
531 }
532
533 pub(crate) fn aggregate_fold_mode_terminal_contract_required() -> Self {
535 Self::query_executor_invariant(
536 "aggregate fold mode must match route fold-mode contract for aggregate terminal",
537 )
538 }
539
540 pub(crate) fn fast_stream_exact_key_count_required() -> Self {
542 Self::query_executor_invariant("fast-path stream must expose an exact key-count hint")
543 }
544
545 pub(crate) fn fast_stream_route_kind_request_match_required() -> Self {
547 Self::query_executor_invariant("fast-stream route kind/request mismatch")
548 }
549
550 pub(crate) fn secondary_index_prefix_spec_required() -> Self {
552 Self::query_executor_invariant(
553 "index-prefix executable spec must be materialized for index-prefix plans",
554 )
555 }
556
557 pub(crate) fn index_range_limit_spec_required() -> Self {
559 Self::query_executor_invariant(
560 "index-range executable spec must be materialized for index-range plans",
561 )
562 }
563
564 pub(crate) fn mutation_atomic_save_duplicate_key(
566 entity_path: &str,
567 key: impl fmt::Display,
568 ) -> Self {
569 Self::executor_unsupported(format!(
570 "atomic save batch rejected duplicate key: entity={entity_path} key={key}",
571 ))
572 }
573
574 pub(crate) fn mutation_index_store_generation_changed(
576 expected_generation: u64,
577 observed_generation: u64,
578 ) -> Self {
579 Self::executor_invariant(format!(
580 "index store generation changed between preflight and apply: expected {expected_generation}, found {observed_generation}",
581 ))
582 }
583
584 #[must_use]
586 #[cold]
587 #[inline(never)]
588 pub(crate) fn executor_invariant_message(reason: impl Into<String>) -> String {
589 format!("executor invariant violated: {}", reason.into())
590 }
591
592 #[cold]
594 #[inline(never)]
595 pub(crate) fn planner_invariant(message: impl Into<String>) -> Self {
596 Self::new(
597 ErrorClass::InvariantViolation,
598 ErrorOrigin::Planner,
599 message.into(),
600 )
601 }
602
603 #[must_use]
605 pub(crate) fn invalid_logical_plan_message(reason: impl Into<String>) -> String {
606 format!("invalid logical plan: {}", reason.into())
607 }
608
609 pub(crate) fn query_invalid_logical_plan(reason: impl Into<String>) -> Self {
611 Self::planner_invariant(Self::invalid_logical_plan_message(reason))
612 }
613
614 #[cold]
616 #[inline(never)]
617 pub(crate) fn query_invariant(message: impl Into<String>) -> Self {
618 Self::new(
619 ErrorClass::InvariantViolation,
620 ErrorOrigin::Query,
621 message.into(),
622 )
623 }
624
625 pub(crate) fn store_invariant(message: impl Into<String>) -> Self {
627 Self::new(
628 ErrorClass::InvariantViolation,
629 ErrorOrigin::Store,
630 message.into(),
631 )
632 }
633
634 pub(crate) fn duplicate_runtime_hooks_for_entity_tag(
636 entity_tag: crate::types::EntityTag,
637 ) -> Self {
638 Self::store_invariant(format!(
639 "duplicate runtime hooks for entity tag '{}'",
640 entity_tag.value()
641 ))
642 }
643
644 pub(crate) fn duplicate_runtime_hooks_for_entity_path(entity_path: &str) -> Self {
646 Self::store_invariant(format!(
647 "duplicate runtime hooks for entity path '{entity_path}'"
648 ))
649 }
650
651 #[cold]
653 #[inline(never)]
654 pub(crate) fn store_internal(message: impl Into<String>) -> Self {
655 Self::new(ErrorClass::Internal, ErrorOrigin::Store, message.into())
656 }
657
658 pub(crate) fn commit_memory_id_unconfigured() -> Self {
660 Self::store_internal(
661 "commit memory id is not configured; initialize recovery before commit store access",
662 )
663 }
664
665 pub(crate) fn commit_memory_id_mismatch(cached_id: u8, configured_id: u8) -> Self {
667 Self::store_internal(format!(
668 "commit memory id mismatch: cached={cached_id}, configured={configured_id}",
669 ))
670 }
671
672 pub(crate) fn commit_memory_registry_init_failed(err: impl fmt::Display) -> Self {
674 Self::store_internal(format!("memory registry init failed: {err}"))
675 }
676
677 pub(crate) fn migration_next_step_index_u64_required(id: &str, version: u64) -> Self {
679 Self::store_internal(format!(
680 "migration '{id}@{version}' next step index does not fit persisted u64 cursor",
681 ))
682 }
683
684 pub(crate) fn recovery_integrity_validation_failed(
686 missing_index_entries: u64,
687 divergent_index_entries: u64,
688 orphan_index_references: u64,
689 ) -> Self {
690 Self::store_corruption(format!(
691 "recovery integrity validation failed: missing_index_entries={missing_index_entries} divergent_index_entries={divergent_index_entries} orphan_index_references={orphan_index_references}",
692 ))
693 }
694
695 #[cold]
697 #[inline(never)]
698 pub(crate) fn index_internal(message: impl Into<String>) -> Self {
699 Self::new(ErrorClass::Internal, ErrorOrigin::Index, message.into())
700 }
701
702 pub(crate) fn structural_index_removal_entity_key_required() -> Self {
704 Self::index_internal("missing old entity key for structural index removal")
705 }
706
707 pub(crate) fn structural_index_insertion_entity_key_required() -> Self {
709 Self::index_internal("missing new entity key for structural index insertion")
710 }
711
712 pub(crate) fn index_commit_op_old_entity_key_required() -> Self {
714 Self::index_internal("missing old entity key for index removal")
715 }
716
717 pub(crate) fn index_commit_op_new_entity_key_required() -> Self {
719 Self::index_internal("missing new entity key for index insertion")
720 }
721
722 #[cfg(test)]
724 pub(crate) fn query_internal(message: impl Into<String>) -> Self {
725 Self::new(ErrorClass::Internal, ErrorOrigin::Query, message.into())
726 }
727
728 #[cold]
730 #[inline(never)]
731 pub(crate) fn query_unsupported(message: impl Into<String>) -> Self {
732 Self::new(ErrorClass::Unsupported, ErrorOrigin::Query, message.into())
733 }
734
735 #[cold]
737 #[inline(never)]
738 pub(crate) fn serialize_internal(message: impl Into<String>) -> Self {
739 Self::new(ErrorClass::Internal, ErrorOrigin::Serialize, message.into())
740 }
741
742 pub(crate) fn persisted_row_encode_failed(detail: impl fmt::Display) -> Self {
744 Self::serialize_internal(format!("row encode failed: {detail}"))
745 }
746
747 pub(crate) fn persisted_row_field_encode_failed(
749 field_name: &str,
750 detail: impl fmt::Display,
751 ) -> Self {
752 Self::serialize_internal(format!(
753 "row encode failed for field '{field_name}': {detail}",
754 ))
755 }
756
757 pub(crate) fn bytes_field_value_encode_failed(detail: impl fmt::Display) -> Self {
759 Self::serialize_internal(format!("bytes(field) value encode failed: {detail}"))
760 }
761
762 pub(crate) fn migration_state_serialize_failed(err: impl fmt::Display) -> Self {
764 Self::serialize_internal(format!("failed to serialize migration state: {err}"))
765 }
766
767 #[cold]
769 #[inline(never)]
770 pub(crate) fn store_corruption(message: impl Into<String>) -> Self {
771 Self::new(ErrorClass::Corruption, ErrorOrigin::Store, message.into())
772 }
773
774 pub(crate) fn multiple_commit_memory_ids_registered(ids: impl fmt::Debug) -> Self {
776 Self::store_corruption(format!(
777 "multiple commit marker memory ids registered: {ids:?}"
778 ))
779 }
780
781 pub(crate) fn migration_persisted_step_index_invalid_usize(
783 id: &str,
784 version: u64,
785 step_index: u64,
786 ) -> Self {
787 Self::store_corruption(format!(
788 "migration '{id}@{version}' persisted step index does not fit runtime usize: {step_index}",
789 ))
790 }
791
792 pub(crate) fn migration_persisted_step_index_out_of_bounds(
794 id: &str,
795 version: u64,
796 step_index: usize,
797 total_steps: usize,
798 ) -> Self {
799 Self::store_corruption(format!(
800 "migration '{id}@{version}' persisted step index out of bounds: {step_index} > {total_steps}",
801 ))
802 }
803
804 pub(crate) fn commit_corruption(detail: impl fmt::Display) -> Self {
806 Self::store_corruption(format!("commit marker corrupted: {detail}"))
807 }
808
809 pub(crate) fn commit_component_corruption(component: &str, detail: impl fmt::Display) -> Self {
811 Self::store_corruption(format!("commit marker {component} corrupted: {detail}"))
812 }
813
814 pub(crate) fn commit_id_generation_failed(detail: impl fmt::Display) -> Self {
816 Self::store_internal(format!("commit id generation failed: {detail}"))
817 }
818
819 pub(crate) fn commit_marker_payload_exceeds_u32_length_limit(label: &str, len: usize) -> Self {
821 Self::store_unsupported(format!("{label} exceeds u32 length limit: {len} bytes"))
822 }
823
824 pub(crate) fn commit_component_length_invalid(
826 component: &str,
827 len: usize,
828 expected: impl fmt::Display,
829 ) -> Self {
830 Self::commit_component_corruption(
831 component,
832 format!("invalid length {len}, expected {expected}"),
833 )
834 }
835
836 pub(crate) fn commit_marker_exceeds_max_size(size: usize, max_size: u32) -> Self {
838 Self::commit_corruption(format!(
839 "commit marker exceeds max size: {size} bytes (limit {max_size})",
840 ))
841 }
842
843 #[cfg(test)]
845 pub(crate) fn commit_marker_exceeds_max_size_before_persist(
846 size: usize,
847 max_size: u32,
848 ) -> Self {
849 Self::store_unsupported(format!(
850 "commit marker exceeds max size: {size} bytes (limit {max_size})",
851 ))
852 }
853
854 pub(crate) fn commit_control_slot_exceeds_max_size(size: usize, max_size: u32) -> Self {
856 Self::store_unsupported(format!(
857 "commit control slot exceeds max size: {size} bytes (limit {max_size})",
858 ))
859 }
860
861 pub(crate) fn commit_control_slot_marker_bytes_exceed_u32_length_limit(size: usize) -> Self {
863 Self::store_unsupported(format!(
864 "commit marker bytes exceed u32 length limit: {size} bytes",
865 ))
866 }
867
868 pub(crate) fn commit_control_slot_migration_bytes_exceed_u32_length_limit(size: usize) -> Self {
870 Self::store_unsupported(format!(
871 "commit migration bytes exceed u32 length limit: {size} bytes",
872 ))
873 }
874
875 pub(crate) fn startup_index_rebuild_invalid_data_key(
877 store_path: &str,
878 detail: impl fmt::Display,
879 ) -> Self {
880 Self::store_corruption(format!(
881 "startup index rebuild failed: invalid data key in store '{store_path}' ({detail})",
882 ))
883 }
884
885 #[cold]
887 #[inline(never)]
888 pub(crate) fn index_corruption(message: impl Into<String>) -> Self {
889 Self::new(ErrorClass::Corruption, ErrorOrigin::Index, message.into())
890 }
891
892 pub(crate) fn index_unique_validation_corruption(
894 entity_path: &str,
895 fields: &str,
896 detail: impl fmt::Display,
897 ) -> Self {
898 Self::index_plan_index_corruption(format!(
899 "index corrupted: {entity_path} ({fields}) -> {detail}",
900 ))
901 }
902
903 pub(crate) fn structural_index_entry_corruption(
905 entity_path: &str,
906 fields: &str,
907 detail: impl fmt::Display,
908 ) -> Self {
909 Self::index_plan_index_corruption(format!(
910 "index corrupted: {entity_path} ({fields}) -> {detail}",
911 ))
912 }
913
914 pub(crate) fn index_unique_validation_entity_key_required() -> Self {
916 Self::index_invariant("missing entity key during unique validation")
917 }
918
919 pub(crate) fn index_unique_validation_row_deserialize_failed(
921 data_key: impl fmt::Display,
922 source: impl fmt::Display,
923 ) -> Self {
924 Self::index_plan_serialize_corruption(format!(
925 "failed to structurally deserialize row: {data_key} ({source})"
926 ))
927 }
928
929 pub(crate) fn index_unique_validation_primary_key_decode_failed(
931 data_key: impl fmt::Display,
932 source: impl fmt::Display,
933 ) -> Self {
934 Self::index_plan_serialize_corruption(format!(
935 "failed to decode structural primary-key slot: {data_key} ({source})"
936 ))
937 }
938
939 pub(crate) fn index_unique_validation_key_rebuild_failed(
941 data_key: impl fmt::Display,
942 entity_path: &str,
943 source: impl fmt::Display,
944 ) -> Self {
945 Self::index_plan_serialize_corruption(format!(
946 "failed to structurally decode unique key row {data_key} for {entity_path}: {source}",
947 ))
948 }
949
950 pub(crate) fn index_unique_validation_row_required(data_key: impl fmt::Display) -> Self {
952 Self::index_plan_store_corruption(format!("missing row: {data_key}"))
953 }
954
955 pub(crate) fn index_only_predicate_component_required() -> Self {
957 Self::index_invariant("index-only predicate program referenced missing index component")
958 }
959
960 pub(crate) fn index_scan_continuation_anchor_within_envelope_required() -> Self {
962 Self::index_invariant(
963 "index-range continuation anchor is outside the requested range envelope",
964 )
965 }
966
967 pub(crate) fn index_scan_continuation_advancement_required() -> Self {
969 Self::index_invariant("index-range continuation scan did not advance beyond the anchor")
970 }
971
972 pub(crate) fn index_scan_key_corrupted_during(
974 context: &'static str,
975 err: impl fmt::Display,
976 ) -> Self {
977 Self::index_corruption(format!("index key corrupted during {context}: {err}"))
978 }
979
980 pub(crate) fn index_projection_component_required(
982 index_name: &str,
983 component_index: usize,
984 ) -> Self {
985 Self::index_invariant(format!(
986 "index projection referenced missing component: index='{index_name}' component_index={component_index}",
987 ))
988 }
989
990 pub(crate) fn unique_index_entry_single_key_required() -> Self {
992 Self::index_corruption("unique index entry contains an unexpected number of keys")
993 }
994
995 pub(crate) fn index_entry_decode_failed(err: impl fmt::Display) -> Self {
997 Self::index_corruption(err.to_string())
998 }
999
1000 pub(crate) fn serialize_corruption(message: impl Into<String>) -> Self {
1002 Self::new(
1003 ErrorClass::Corruption,
1004 ErrorOrigin::Serialize,
1005 message.into(),
1006 )
1007 }
1008
1009 pub(crate) fn persisted_row_decode_failed(detail: impl fmt::Display) -> Self {
1011 Self::serialize_corruption(format!("row decode: {detail}"))
1012 }
1013
1014 pub(crate) fn persisted_row_field_decode_failed(
1016 field_name: &str,
1017 detail: impl fmt::Display,
1018 ) -> Self {
1019 Self::serialize_corruption(format!(
1020 "row decode failed for field '{field_name}': {detail}",
1021 ))
1022 }
1023
1024 pub(crate) fn persisted_row_field_kind_decode_failed(
1026 field_name: &str,
1027 field_kind: impl fmt::Debug,
1028 detail: impl fmt::Display,
1029 ) -> Self {
1030 Self::persisted_row_field_decode_failed(
1031 field_name,
1032 format!("kind={field_kind:?}: {detail}"),
1033 )
1034 }
1035
1036 pub(crate) fn persisted_row_field_payload_exact_len_required(
1038 field_name: &str,
1039 payload_kind: &str,
1040 expected_len: usize,
1041 ) -> Self {
1042 let unit = if expected_len == 1 { "byte" } else { "bytes" };
1043
1044 Self::persisted_row_field_decode_failed(
1045 field_name,
1046 format!("{payload_kind} payload must be exactly {expected_len} {unit}"),
1047 )
1048 }
1049
1050 pub(crate) fn persisted_row_field_payload_must_be_empty(
1052 field_name: &str,
1053 payload_kind: &str,
1054 ) -> Self {
1055 Self::persisted_row_field_decode_failed(
1056 field_name,
1057 format!("{payload_kind} payload must be empty"),
1058 )
1059 }
1060
1061 pub(crate) fn persisted_row_field_payload_invalid_byte(
1063 field_name: &str,
1064 payload_kind: &str,
1065 value: u8,
1066 ) -> Self {
1067 Self::persisted_row_field_decode_failed(
1068 field_name,
1069 format!("invalid {payload_kind} payload byte {value}"),
1070 )
1071 }
1072
1073 pub(crate) fn persisted_row_field_payload_non_finite(
1075 field_name: &str,
1076 payload_kind: &str,
1077 ) -> Self {
1078 Self::persisted_row_field_decode_failed(
1079 field_name,
1080 format!("{payload_kind} payload is non-finite"),
1081 )
1082 }
1083
1084 pub(crate) fn persisted_row_field_payload_out_of_range(
1086 field_name: &str,
1087 payload_kind: &str,
1088 ) -> Self {
1089 Self::persisted_row_field_decode_failed(
1090 field_name,
1091 format!("{payload_kind} payload out of range for target type"),
1092 )
1093 }
1094
1095 pub(crate) fn persisted_row_field_text_payload_invalid_utf8(
1097 field_name: &str,
1098 detail: impl fmt::Display,
1099 ) -> Self {
1100 Self::persisted_row_field_decode_failed(
1101 field_name,
1102 format!("invalid UTF-8 text payload ({detail})"),
1103 )
1104 }
1105
1106 pub(crate) fn persisted_row_slot_lookup_out_of_bounds(model_path: &str, slot: usize) -> Self {
1108 Self::index_invariant(format!(
1109 "slot lookup outside model bounds during structural row access: model='{model_path}' slot={slot}",
1110 ))
1111 }
1112
1113 pub(crate) fn persisted_row_slot_cache_lookup_out_of_bounds(
1115 model_path: &str,
1116 slot: usize,
1117 ) -> Self {
1118 Self::index_invariant(format!(
1119 "slot cache lookup outside model bounds during structural row access: model='{model_path}' slot={slot}",
1120 ))
1121 }
1122
1123 pub(crate) fn persisted_row_primary_key_not_storage_encodable(
1125 data_key: impl fmt::Display,
1126 detail: impl fmt::Display,
1127 ) -> Self {
1128 Self::persisted_row_decode_failed(format!(
1129 "primary-key value is not storage-key encodable: {data_key} ({detail})",
1130 ))
1131 }
1132
1133 pub(crate) fn persisted_row_primary_key_slot_missing(data_key: impl fmt::Display) -> Self {
1135 Self::persisted_row_decode_failed(format!(
1136 "missing primary-key slot while validating {data_key}",
1137 ))
1138 }
1139
1140 pub(crate) fn persisted_row_key_mismatch(
1142 expected_key: impl fmt::Display,
1143 found_key: impl fmt::Display,
1144 ) -> Self {
1145 Self::store_corruption(format!(
1146 "row key mismatch: expected {expected_key}, found {found_key}",
1147 ))
1148 }
1149
1150 pub(crate) fn persisted_row_declared_field_missing(field_name: &str) -> Self {
1152 Self::persisted_row_decode_failed(format!("missing declared field `{field_name}`"))
1153 }
1154
1155 pub(crate) fn data_key_entity_mismatch(
1157 expected: impl fmt::Display,
1158 found: impl fmt::Display,
1159 ) -> Self {
1160 Self::store_corruption(format!(
1161 "data key entity mismatch: expected {expected}, found {found}",
1162 ))
1163 }
1164
1165 pub(crate) fn data_key_primary_key_decode_failed(value: impl fmt::Debug) -> Self {
1167 Self::store_corruption(format!("data key primary key decode failed: {value:?}",))
1168 }
1169
1170 pub(crate) fn reverse_index_ordinal_overflow(
1172 source_path: &str,
1173 field_name: &str,
1174 target_path: &str,
1175 detail: impl fmt::Display,
1176 ) -> Self {
1177 Self::index_internal(format!(
1178 "reverse index ordinal overflow: source={source_path} field={field_name} target={target_path} ({detail})",
1179 ))
1180 }
1181
1182 pub(crate) fn reverse_index_entry_corrupted(
1184 source_path: &str,
1185 field_name: &str,
1186 target_path: &str,
1187 index_key: impl fmt::Debug,
1188 detail: impl fmt::Display,
1189 ) -> Self {
1190 Self::index_corruption(format!(
1191 "reverse index entry corrupted: source={source_path} field={field_name} target={target_path} key={index_key:?} ({detail})",
1192 ))
1193 }
1194
1195 pub(crate) fn reverse_index_entry_encode_failed(
1197 source_path: &str,
1198 field_name: &str,
1199 target_path: &str,
1200 detail: impl fmt::Display,
1201 ) -> Self {
1202 Self::index_unsupported(format!(
1203 "reverse index entry encoding failed: source={source_path} field={field_name} target={target_path} ({detail})",
1204 ))
1205 }
1206
1207 pub(crate) fn relation_target_store_missing(
1209 source_path: &str,
1210 field_name: &str,
1211 target_path: &str,
1212 store_path: &str,
1213 detail: impl fmt::Display,
1214 ) -> Self {
1215 Self::executor_internal(format!(
1216 "relation target store missing: source={source_path} field={field_name} target={target_path} store={store_path} ({detail})",
1217 ))
1218 }
1219
1220 pub(crate) fn relation_target_key_decode_failed(
1222 context_label: &str,
1223 source_path: &str,
1224 field_name: &str,
1225 target_path: &str,
1226 detail: impl fmt::Display,
1227 ) -> Self {
1228 Self::identity_corruption(format!(
1229 "{context_label}: source={source_path} field={field_name} target={target_path} ({detail})",
1230 ))
1231 }
1232
1233 pub(crate) fn relation_target_entity_mismatch(
1235 context_label: &str,
1236 source_path: &str,
1237 field_name: &str,
1238 target_path: &str,
1239 target_entity_name: &str,
1240 expected_tag: impl fmt::Display,
1241 actual_tag: impl fmt::Display,
1242 ) -> Self {
1243 Self::store_corruption(format!(
1244 "{context_label}: source={source_path} field={field_name} target={target_path} expected={target_entity_name} (tag={expected_tag}) actual_tag={actual_tag}",
1245 ))
1246 }
1247
1248 pub(crate) fn relation_source_row_decode_failed(
1250 source_path: &str,
1251 field_name: &str,
1252 target_path: &str,
1253 detail: impl fmt::Display,
1254 ) -> Self {
1255 Self::serialize_corruption(format!(
1256 "relation source row decode: source={source_path} field={field_name} target={target_path} ({detail})",
1257 ))
1258 }
1259
1260 pub(crate) fn relation_source_row_unsupported_scalar_relation_key(
1262 source_path: &str,
1263 field_name: &str,
1264 target_path: &str,
1265 ) -> Self {
1266 Self::serialize_corruption(format!(
1267 "relation source row decode: unsupported scalar relation key: source={source_path} field={field_name} target={target_path}",
1268 ))
1269 }
1270
1271 pub(crate) fn relation_source_row_invalid_field_kind(field_kind: impl fmt::Debug) -> Self {
1273 Self::serialize_corruption(format!(
1274 "invalid strong relation field kind during structural decode: {field_kind:?}"
1275 ))
1276 }
1277
1278 pub(crate) fn relation_source_row_unsupported_key_kind(field_kind: impl fmt::Debug) -> Self {
1280 Self::serialize_corruption(format!(
1281 "unsupported strong relation key kind during structural decode: {field_kind:?}"
1282 ))
1283 }
1284
1285 pub(crate) fn reverse_index_relation_target_decode_invariant_violated(
1287 source_path: &str,
1288 field_name: &str,
1289 target_path: &str,
1290 ) -> Self {
1291 Self::executor_internal(format!(
1292 "relation target decode invariant violated while preparing reverse index: source={source_path} field={field_name} target={target_path}",
1293 ))
1294 }
1295
1296 pub(crate) fn bytes_covering_component_payload_empty() -> Self {
1298 Self::index_corruption("index component payload is empty during covering projection decode")
1299 }
1300
1301 pub(crate) fn bytes_covering_bool_payload_truncated() -> Self {
1303 Self::index_corruption("bool covering component payload is truncated")
1304 }
1305
1306 pub(crate) fn bytes_covering_component_payload_invalid_length(payload_kind: &str) -> Self {
1308 Self::index_corruption(format!(
1309 "{payload_kind} covering component payload has invalid length"
1310 ))
1311 }
1312
1313 pub(crate) fn bytes_covering_bool_payload_invalid_value() -> Self {
1315 Self::index_corruption("bool covering component payload has invalid value")
1316 }
1317
1318 pub(crate) fn bytes_covering_text_payload_invalid_terminator() -> Self {
1320 Self::index_corruption("text covering component payload has invalid terminator")
1321 }
1322
1323 pub(crate) fn bytes_covering_text_payload_trailing_bytes() -> Self {
1325 Self::index_corruption("text covering component payload contains trailing bytes")
1326 }
1327
1328 pub(crate) fn bytes_covering_text_payload_invalid_utf8() -> Self {
1330 Self::index_corruption("text covering component payload is not valid UTF-8")
1331 }
1332
1333 pub(crate) fn bytes_covering_text_payload_invalid_escape_byte() -> Self {
1335 Self::index_corruption("text covering component payload has invalid escape byte")
1336 }
1337
1338 pub(crate) fn bytes_covering_text_payload_missing_terminator() -> Self {
1340 Self::index_corruption("text covering component payload is missing terminator")
1341 }
1342
1343 #[must_use]
1345 pub fn missing_persisted_slot(field_name: &'static str) -> Self {
1346 Self::serialize_corruption(format!("row decode: missing required field '{field_name}'",))
1347 }
1348
1349 pub(crate) fn identity_corruption(message: impl Into<String>) -> Self {
1351 Self::new(
1352 ErrorClass::Corruption,
1353 ErrorOrigin::Identity,
1354 message.into(),
1355 )
1356 }
1357
1358 #[cold]
1360 #[inline(never)]
1361 pub(crate) fn store_unsupported(message: impl Into<String>) -> Self {
1362 Self::new(ErrorClass::Unsupported, ErrorOrigin::Store, message.into())
1363 }
1364
1365 pub(crate) fn migration_label_empty(label: &str) -> Self {
1367 Self::store_unsupported(format!("{label} cannot be empty"))
1368 }
1369
1370 pub(crate) fn migration_step_row_ops_required(name: &str) -> Self {
1372 Self::store_unsupported(format!(
1373 "migration step '{name}' must include at least one row op",
1374 ))
1375 }
1376
1377 pub(crate) fn migration_plan_version_required(id: &str) -> Self {
1379 Self::store_unsupported(format!("migration plan '{id}' version must be > 0",))
1380 }
1381
1382 pub(crate) fn migration_plan_steps_required(id: &str) -> Self {
1384 Self::store_unsupported(format!(
1385 "migration plan '{id}' must include at least one step",
1386 ))
1387 }
1388
1389 pub(crate) fn migration_cursor_out_of_bounds(
1391 id: &str,
1392 version: u64,
1393 next_step: usize,
1394 total_steps: usize,
1395 ) -> Self {
1396 Self::store_unsupported(format!(
1397 "migration '{id}@{version}' cursor out of bounds: next_step={next_step} total_steps={total_steps}",
1398 ))
1399 }
1400
1401 pub(crate) fn migration_execution_requires_max_steps(id: &str) -> Self {
1403 Self::store_unsupported(format!("migration '{id}' execution requires max_steps > 0",))
1404 }
1405
1406 pub(crate) fn migration_in_progress_conflict(
1408 requested_id: &str,
1409 requested_version: u64,
1410 active_id: &str,
1411 active_version: u64,
1412 ) -> Self {
1413 Self::store_unsupported(format!(
1414 "migration '{requested_id}@{requested_version}' cannot execute while migration '{active_id}@{active_version}' is in progress",
1415 ))
1416 }
1417
1418 pub(crate) fn unsupported_entity_tag_in_data_store(
1420 entity_tag: crate::types::EntityTag,
1421 ) -> Self {
1422 Self::store_unsupported(format!(
1423 "unsupported entity tag in data store: '{}'",
1424 entity_tag.value()
1425 ))
1426 }
1427
1428 pub(crate) fn configured_commit_memory_id_mismatch(
1430 configured_id: u8,
1431 registered_id: u8,
1432 ) -> Self {
1433 Self::store_unsupported(format!(
1434 "configured commit memory id {configured_id} does not match existing commit marker id {registered_id}",
1435 ))
1436 }
1437
1438 pub(crate) fn commit_memory_id_already_registered(memory_id: u8, label: &str) -> Self {
1440 Self::store_unsupported(format!(
1441 "configured commit memory id {memory_id} is already registered as '{label}'",
1442 ))
1443 }
1444
1445 pub(crate) fn commit_memory_id_outside_reserved_ranges(memory_id: u8) -> Self {
1447 Self::store_unsupported(format!(
1448 "configured commit memory id {memory_id} is outside reserved ranges",
1449 ))
1450 }
1451
1452 pub(crate) fn commit_memory_id_registration_failed(err: impl fmt::Display) -> Self {
1454 Self::store_internal(format!("commit memory id registration failed: {err}"))
1455 }
1456
1457 pub(crate) fn index_unsupported(message: impl Into<String>) -> Self {
1459 Self::new(ErrorClass::Unsupported, ErrorOrigin::Index, message.into())
1460 }
1461
1462 pub(crate) fn index_component_exceeds_max_size(
1464 key_item: impl fmt::Display,
1465 len: usize,
1466 max_component_size: usize,
1467 ) -> Self {
1468 Self::index_unsupported(format!(
1469 "index component exceeds max size: key item '{key_item}' -> {len} bytes (limit {max_component_size})",
1470 ))
1471 }
1472
1473 pub(crate) fn index_entry_exceeds_max_keys(
1475 entity_path: &str,
1476 fields: &str,
1477 keys: usize,
1478 ) -> Self {
1479 Self::index_unsupported(format!(
1480 "index entry exceeds max keys: {entity_path} ({fields}) -> {keys} keys",
1481 ))
1482 }
1483
1484 #[cfg(test)]
1486 pub(crate) fn index_entry_duplicate_keys_unexpected(entity_path: &str, fields: &str) -> Self {
1487 Self::index_invariant(format!(
1488 "index entry unexpectedly contains duplicate keys: {entity_path} ({fields})",
1489 ))
1490 }
1491
1492 pub(crate) fn index_entry_key_encoding_failed(
1494 entity_path: &str,
1495 fields: &str,
1496 err: impl fmt::Display,
1497 ) -> Self {
1498 Self::index_unsupported(format!(
1499 "index entry key encoding failed: {entity_path} ({fields}) -> {err}",
1500 ))
1501 }
1502
1503 pub(crate) fn serialize_unsupported(message: impl Into<String>) -> Self {
1505 Self::new(
1506 ErrorClass::Unsupported,
1507 ErrorOrigin::Serialize,
1508 message.into(),
1509 )
1510 }
1511
1512 pub(crate) fn cursor_unsupported(message: impl Into<String>) -> Self {
1514 Self::new(ErrorClass::Unsupported, ErrorOrigin::Cursor, message.into())
1515 }
1516
1517 pub(crate) fn serialize_incompatible_persisted_format(message: impl Into<String>) -> Self {
1519 Self::new(
1520 ErrorClass::IncompatiblePersistedFormat,
1521 ErrorOrigin::Serialize,
1522 message.into(),
1523 )
1524 }
1525
1526 pub(crate) fn serialize_payload_decode_failed(
1529 source: SerializeError,
1530 payload_label: &'static str,
1531 ) -> Self {
1532 match source {
1533 SerializeError::DeserializeSizeLimitExceeded { len, max_bytes } => {
1536 Self::serialize_corruption(format!(
1537 "{payload_label} decode failed: payload size {len} exceeds limit {max_bytes}"
1538 ))
1539 }
1540 SerializeError::Deserialize(_) => Self::serialize_corruption(format!(
1541 "{payload_label} decode failed: {}",
1542 SerializeErrorKind::Deserialize
1543 )),
1544 SerializeError::Serialize(_) => Self::serialize_corruption(format!(
1545 "{payload_label} decode failed: {}",
1546 SerializeErrorKind::Serialize
1547 )),
1548 }
1549 }
1550
1551 #[cfg(feature = "sql")]
1554 pub(crate) fn query_unsupported_sql_feature(feature: &'static str) -> Self {
1555 let message = format!(
1556 "SQL query is not executable in this release: unsupported SQL feature: {feature}"
1557 );
1558
1559 Self {
1560 class: ErrorClass::Unsupported,
1561 origin: ErrorOrigin::Query,
1562 message,
1563 detail: Some(ErrorDetail::Query(
1564 QueryErrorDetail::UnsupportedSqlFeature { feature },
1565 )),
1566 }
1567 }
1568
1569 pub fn store_not_found(key: impl Into<String>) -> Self {
1570 let key = key.into();
1571
1572 Self {
1573 class: ErrorClass::NotFound,
1574 origin: ErrorOrigin::Store,
1575 message: format!("data key not found: {key}"),
1576 detail: Some(ErrorDetail::Store(StoreError::NotFound { key })),
1577 }
1578 }
1579
1580 pub fn unsupported_entity_path(path: impl Into<String>) -> Self {
1582 let path = path.into();
1583
1584 Self::new(
1585 ErrorClass::Unsupported,
1586 ErrorOrigin::Store,
1587 format!("unsupported entity path: '{path}'"),
1588 )
1589 }
1590
1591 #[must_use]
1592 pub const fn is_not_found(&self) -> bool {
1593 matches!(
1594 self.detail,
1595 Some(ErrorDetail::Store(StoreError::NotFound { .. }))
1596 )
1597 }
1598
1599 #[must_use]
1600 pub fn display_with_class(&self) -> String {
1601 format!("{}:{}: {}", self.origin, self.class, self.message)
1602 }
1603
1604 #[cold]
1606 #[inline(never)]
1607 pub(crate) fn index_plan_corruption(origin: ErrorOrigin, message: impl Into<String>) -> Self {
1608 let message = message.into();
1609 Self::new(
1610 ErrorClass::Corruption,
1611 origin,
1612 format!("corruption detected ({origin}): {message}"),
1613 )
1614 }
1615
1616 #[cold]
1618 #[inline(never)]
1619 pub(crate) fn index_plan_index_corruption(message: impl Into<String>) -> Self {
1620 Self::index_plan_corruption(ErrorOrigin::Index, message)
1621 }
1622
1623 #[cold]
1625 #[inline(never)]
1626 pub(crate) fn index_plan_store_corruption(message: impl Into<String>) -> Self {
1627 Self::index_plan_corruption(ErrorOrigin::Store, message)
1628 }
1629
1630 #[cold]
1632 #[inline(never)]
1633 pub(crate) fn index_plan_serialize_corruption(message: impl Into<String>) -> Self {
1634 Self::index_plan_corruption(ErrorOrigin::Serialize, message)
1635 }
1636
1637 #[cfg(test)]
1639 pub(crate) fn index_plan_invariant(origin: ErrorOrigin, message: impl Into<String>) -> Self {
1640 let message = message.into();
1641 Self::new(
1642 ErrorClass::InvariantViolation,
1643 origin,
1644 format!("invariant violation detected ({origin}): {message}"),
1645 )
1646 }
1647
1648 #[cfg(test)]
1650 pub(crate) fn index_plan_store_invariant(message: impl Into<String>) -> Self {
1651 Self::index_plan_invariant(ErrorOrigin::Store, message)
1652 }
1653
1654 pub(crate) fn index_violation(path: &str, index_fields: &[&str]) -> Self {
1656 Self::new(
1657 ErrorClass::Conflict,
1658 ErrorOrigin::Index,
1659 format!(
1660 "index constraint violation: {path} ({})",
1661 index_fields.join(", ")
1662 ),
1663 )
1664 }
1665}
1666
1667#[derive(Debug, ThisError)]
1675pub enum ErrorDetail {
1676 #[error("{0}")]
1677 Store(StoreError),
1678 #[error("{0}")]
1679 Query(QueryErrorDetail),
1680 }
1687
1688#[derive(Debug, ThisError)]
1696pub enum StoreError {
1697 #[error("key not found: {key}")]
1698 NotFound { key: String },
1699
1700 #[error("store corruption: {message}")]
1701 Corrupt { message: String },
1702
1703 #[error("store invariant violation: {message}")]
1704 InvariantViolation { message: String },
1705}
1706
1707#[derive(Debug, ThisError)]
1714pub enum QueryErrorDetail {
1715 #[error("unsupported SQL feature: {feature}")]
1716 UnsupportedSqlFeature { feature: &'static str },
1717}
1718
1719#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1726pub enum ErrorClass {
1727 Corruption,
1728 IncompatiblePersistedFormat,
1729 NotFound,
1730 Internal,
1731 Conflict,
1732 Unsupported,
1733 InvariantViolation,
1734}
1735
1736impl fmt::Display for ErrorClass {
1737 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1738 let label = match self {
1739 Self::Corruption => "corruption",
1740 Self::IncompatiblePersistedFormat => "incompatible_persisted_format",
1741 Self::NotFound => "not_found",
1742 Self::Internal => "internal",
1743 Self::Conflict => "conflict",
1744 Self::Unsupported => "unsupported",
1745 Self::InvariantViolation => "invariant_violation",
1746 };
1747 write!(f, "{label}")
1748 }
1749}
1750
1751#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1758pub enum ErrorOrigin {
1759 Serialize,
1760 Store,
1761 Index,
1762 Identity,
1763 Query,
1764 Planner,
1765 Cursor,
1766 Recovery,
1767 Response,
1768 Executor,
1769 Interface,
1770}
1771
1772impl fmt::Display for ErrorOrigin {
1773 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1774 let label = match self {
1775 Self::Serialize => "serialize",
1776 Self::Store => "store",
1777 Self::Index => "index",
1778 Self::Identity => "identity",
1779 Self::Query => "query",
1780 Self::Planner => "planner",
1781 Self::Cursor => "cursor",
1782 Self::Recovery => "recovery",
1783 Self::Response => "response",
1784 Self::Executor => "executor",
1785 Self::Interface => "interface",
1786 };
1787 write!(f, "{label}")
1788 }
1789}