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_schema_invalid(
329 entity_path: &str,
330 detail: impl fmt::Display,
331 ) -> Self {
332 Self::executor_invariant(format!("entity schema invalid for {entity_path}: {detail}"))
333 }
334
335 pub(crate) fn mutation_entity_primary_key_missing(entity_path: &str, field_name: &str) -> Self {
337 Self::executor_invariant(format!(
338 "entity primary key field missing: {entity_path} field={field_name}",
339 ))
340 }
341
342 pub(crate) fn mutation_entity_primary_key_invalid_value(
344 entity_path: &str,
345 field_name: &str,
346 value: &crate::value::Value,
347 ) -> Self {
348 Self::executor_invariant(format!(
349 "entity primary key field has invalid value: {entity_path} field={field_name} value={value:?}",
350 ))
351 }
352
353 pub(crate) fn mutation_entity_primary_key_type_mismatch(
355 entity_path: &str,
356 field_name: &str,
357 value: &crate::value::Value,
358 ) -> Self {
359 Self::executor_invariant(format!(
360 "entity primary key field type mismatch: {entity_path} field={field_name} value={value:?}",
361 ))
362 }
363
364 pub(crate) fn mutation_entity_primary_key_mismatch(
366 entity_path: &str,
367 field_name: &str,
368 field_value: &crate::value::Value,
369 identity_key: &crate::value::Value,
370 ) -> Self {
371 Self::executor_invariant(format!(
372 "entity primary key mismatch: {entity_path} field={field_name} field_value={field_value:?} id_key={identity_key:?}",
373 ))
374 }
375
376 pub(crate) fn mutation_entity_field_missing(
378 entity_path: &str,
379 field_name: &str,
380 indexed: bool,
381 ) -> Self {
382 let indexed_note = if indexed { " (indexed)" } else { "" };
383
384 Self::executor_invariant(format!(
385 "entity field missing: {entity_path} field={field_name}{indexed_note}",
386 ))
387 }
388
389 pub(crate) fn mutation_entity_field_type_mismatch(
391 entity_path: &str,
392 field_name: &str,
393 value: &crate::value::Value,
394 ) -> Self {
395 Self::executor_invariant(format!(
396 "entity field type mismatch: {entity_path} field={field_name} value={value:?}",
397 ))
398 }
399
400 #[allow(dead_code)]
405 pub(crate) fn mutation_structural_after_image_invalid(
406 entity_path: &str,
407 data_key: impl fmt::Display,
408 detail: impl AsRef<str>,
409 ) -> Self {
410 Self::executor_invariant(format!(
411 "mutation result is invalid: {entity_path} key={data_key} ({})",
412 detail.as_ref(),
413 ))
414 }
415
416 pub(crate) fn mutation_structural_field_unknown(entity_path: &str, field_name: &str) -> Self {
418 Self::executor_invariant(format!(
419 "mutation field not found: {entity_path} field={field_name}",
420 ))
421 }
422
423 pub(crate) fn mutation_decimal_scale_mismatch(
425 entity_path: &str,
426 field_name: &str,
427 expected_scale: impl fmt::Display,
428 actual_scale: impl fmt::Display,
429 ) -> Self {
430 Self::executor_unsupported(format!(
431 "decimal field scale mismatch: {entity_path} field={field_name} expected_scale={expected_scale} actual_scale={actual_scale}",
432 ))
433 }
434
435 pub(crate) fn mutation_set_field_list_required(entity_path: &str, field_name: &str) -> Self {
437 Self::executor_invariant(format!(
438 "set field must encode as Value::List: {entity_path} field={field_name}",
439 ))
440 }
441
442 pub(crate) fn mutation_set_field_not_canonical(entity_path: &str, field_name: &str) -> Self {
444 Self::executor_invariant(format!(
445 "set field must be strictly ordered and deduplicated: {entity_path} field={field_name}",
446 ))
447 }
448
449 pub(crate) fn mutation_map_field_map_required(entity_path: &str, field_name: &str) -> Self {
451 Self::executor_invariant(format!(
452 "map field must encode as Value::Map: {entity_path} field={field_name}",
453 ))
454 }
455
456 pub(crate) fn mutation_map_field_entries_invalid(
458 entity_path: &str,
459 field_name: &str,
460 detail: impl fmt::Display,
461 ) -> Self {
462 Self::executor_invariant(format!(
463 "map field entries violate map invariants: {entity_path} field={field_name} ({detail})",
464 ))
465 }
466
467 pub(crate) fn mutation_map_field_entries_not_canonical(
469 entity_path: &str,
470 field_name: &str,
471 ) -> Self {
472 Self::executor_invariant(format!(
473 "map field entries are not in canonical deterministic order: {entity_path} field={field_name}",
474 ))
475 }
476
477 pub(crate) fn scalar_page_predicate_slots_required() -> Self {
479 Self::query_executor_invariant("post-access filtering requires precompiled predicate slots")
480 }
481
482 pub(crate) fn scalar_page_ordering_after_filtering_required() -> Self {
484 Self::query_executor_invariant("ordering must run after filtering")
485 }
486
487 pub(crate) fn scalar_page_cursor_boundary_order_required() -> Self {
489 Self::query_executor_invariant("cursor boundary requires ordering")
490 }
491
492 pub(crate) fn scalar_page_cursor_boundary_after_ordering_required() -> Self {
494 Self::query_executor_invariant("cursor boundary must run after ordering")
495 }
496
497 pub(crate) fn scalar_page_pagination_after_ordering_required() -> Self {
499 Self::query_executor_invariant("pagination must run after ordering")
500 }
501
502 pub(crate) fn scalar_page_delete_limit_after_ordering_required() -> Self {
504 Self::query_executor_invariant("delete limit must run after ordering")
505 }
506
507 pub(crate) fn load_runtime_scalar_payload_required() -> Self {
509 Self::query_executor_invariant("scalar load mode must carry scalar runtime payload")
510 }
511
512 pub(crate) fn load_runtime_grouped_payload_required() -> Self {
514 Self::query_executor_invariant("grouped load mode must carry grouped runtime payload")
515 }
516
517 pub(crate) fn load_runtime_scalar_surface_payload_required() -> Self {
519 Self::query_executor_invariant("scalar page load mode must carry scalar runtime payload")
520 }
521
522 pub(crate) fn load_runtime_grouped_surface_payload_required() -> Self {
524 Self::query_executor_invariant("grouped page load mode must carry grouped runtime payload")
525 }
526
527 pub(crate) fn load_executor_load_plan_required() -> Self {
529 Self::query_executor_invariant("load executor requires load plans")
530 }
531
532 pub(crate) fn delete_executor_grouped_unsupported() -> Self {
534 Self::executor_unsupported("grouped query execution is not yet enabled in this release")
535 }
536
537 pub(crate) fn delete_executor_delete_plan_required() -> Self {
539 Self::query_executor_invariant("delete executor requires delete plans")
540 }
541
542 pub(crate) fn aggregate_fold_mode_terminal_contract_required() -> Self {
544 Self::query_executor_invariant(
545 "aggregate fold mode must match route fold-mode contract for aggregate terminal",
546 )
547 }
548
549 pub(crate) fn fast_stream_exact_key_count_required() -> Self {
551 Self::query_executor_invariant("fast-path stream must expose an exact key-count hint")
552 }
553
554 pub(crate) fn fast_stream_route_kind_request_match_required() -> Self {
556 Self::query_executor_invariant("fast-stream route kind/request mismatch")
557 }
558
559 pub(crate) fn secondary_index_prefix_spec_required() -> Self {
561 Self::query_executor_invariant(
562 "index-prefix executable spec must be materialized for index-prefix plans",
563 )
564 }
565
566 pub(crate) fn index_range_limit_spec_required() -> Self {
568 Self::query_executor_invariant(
569 "index-range executable spec must be materialized for index-range plans",
570 )
571 }
572
573 pub(crate) fn mutation_atomic_save_duplicate_key(
575 entity_path: &str,
576 key: impl fmt::Display,
577 ) -> Self {
578 Self::executor_unsupported(format!(
579 "atomic save batch rejected duplicate key: entity={entity_path} key={key}",
580 ))
581 }
582
583 pub(crate) fn mutation_index_store_generation_changed(
585 expected_generation: u64,
586 observed_generation: u64,
587 ) -> Self {
588 Self::executor_invariant(format!(
589 "index store generation changed between preflight and apply: expected {expected_generation}, found {observed_generation}",
590 ))
591 }
592
593 #[must_use]
595 #[cold]
596 #[inline(never)]
597 pub(crate) fn executor_invariant_message(reason: impl Into<String>) -> String {
598 format!("executor invariant violated: {}", reason.into())
599 }
600
601 #[cold]
603 #[inline(never)]
604 pub(crate) fn planner_invariant(message: impl Into<String>) -> Self {
605 Self::new(
606 ErrorClass::InvariantViolation,
607 ErrorOrigin::Planner,
608 message.into(),
609 )
610 }
611
612 #[must_use]
614 pub(crate) fn invalid_logical_plan_message(reason: impl Into<String>) -> String {
615 format!("invalid logical plan: {}", reason.into())
616 }
617
618 pub(crate) fn query_invalid_logical_plan(reason: impl Into<String>) -> Self {
620 Self::planner_invariant(Self::invalid_logical_plan_message(reason))
621 }
622
623 #[cold]
625 #[inline(never)]
626 pub(crate) fn query_invariant(message: impl Into<String>) -> Self {
627 Self::new(
628 ErrorClass::InvariantViolation,
629 ErrorOrigin::Query,
630 message.into(),
631 )
632 }
633
634 pub(crate) fn store_invariant(message: impl Into<String>) -> Self {
636 Self::new(
637 ErrorClass::InvariantViolation,
638 ErrorOrigin::Store,
639 message.into(),
640 )
641 }
642
643 pub(crate) fn duplicate_runtime_hooks_for_entity_tag(
645 entity_tag: crate::types::EntityTag,
646 ) -> Self {
647 Self::store_invariant(format!(
648 "duplicate runtime hooks for entity tag '{}'",
649 entity_tag.value()
650 ))
651 }
652
653 pub(crate) fn duplicate_runtime_hooks_for_entity_path(entity_path: &str) -> Self {
655 Self::store_invariant(format!(
656 "duplicate runtime hooks for entity path '{entity_path}'"
657 ))
658 }
659
660 #[cold]
662 #[inline(never)]
663 pub(crate) fn store_internal(message: impl Into<String>) -> Self {
664 Self::new(ErrorClass::Internal, ErrorOrigin::Store, message.into())
665 }
666
667 pub(crate) fn commit_memory_id_unconfigured() -> Self {
669 Self::store_internal(
670 "commit memory id is not configured; initialize recovery before commit store access",
671 )
672 }
673
674 pub(crate) fn commit_memory_id_mismatch(cached_id: u8, configured_id: u8) -> Self {
676 Self::store_internal(format!(
677 "commit memory id mismatch: cached={cached_id}, configured={configured_id}",
678 ))
679 }
680
681 pub(crate) fn commit_memory_registry_init_failed(err: impl fmt::Display) -> Self {
683 Self::store_internal(format!("memory registry init failed: {err}"))
684 }
685
686 pub(crate) fn migration_next_step_index_u64_required(id: &str, version: u64) -> Self {
688 Self::store_internal(format!(
689 "migration '{id}@{version}' next step index does not fit persisted u64 cursor",
690 ))
691 }
692
693 pub(crate) fn recovery_integrity_validation_failed(
695 missing_index_entries: u64,
696 divergent_index_entries: u64,
697 orphan_index_references: u64,
698 ) -> Self {
699 Self::store_corruption(format!(
700 "recovery integrity validation failed: missing_index_entries={missing_index_entries} divergent_index_entries={divergent_index_entries} orphan_index_references={orphan_index_references}",
701 ))
702 }
703
704 #[cold]
706 #[inline(never)]
707 pub(crate) fn index_internal(message: impl Into<String>) -> Self {
708 Self::new(ErrorClass::Internal, ErrorOrigin::Index, message.into())
709 }
710
711 pub(crate) fn structural_index_removal_entity_key_required() -> Self {
713 Self::index_internal("missing old entity key for structural index removal")
714 }
715
716 pub(crate) fn structural_index_insertion_entity_key_required() -> Self {
718 Self::index_internal("missing new entity key for structural index insertion")
719 }
720
721 pub(crate) fn index_commit_op_old_entity_key_required() -> Self {
723 Self::index_internal("missing old entity key for index removal")
724 }
725
726 pub(crate) fn index_commit_op_new_entity_key_required() -> Self {
728 Self::index_internal("missing new entity key for index insertion")
729 }
730
731 #[cfg(test)]
733 pub(crate) fn query_internal(message: impl Into<String>) -> Self {
734 Self::new(ErrorClass::Internal, ErrorOrigin::Query, message.into())
735 }
736
737 #[cold]
739 #[inline(never)]
740 pub(crate) fn query_unsupported(message: impl Into<String>) -> Self {
741 Self::new(ErrorClass::Unsupported, ErrorOrigin::Query, message.into())
742 }
743
744 #[cold]
746 #[inline(never)]
747 pub(crate) fn serialize_internal(message: impl Into<String>) -> Self {
748 Self::new(ErrorClass::Internal, ErrorOrigin::Serialize, message.into())
749 }
750
751 pub(crate) fn persisted_row_encode_failed(detail: impl fmt::Display) -> Self {
753 Self::serialize_internal(format!("row encode failed: {detail}"))
754 }
755
756 pub(crate) fn persisted_row_field_encode_failed(
758 field_name: &str,
759 detail: impl fmt::Display,
760 ) -> Self {
761 Self::serialize_internal(format!(
762 "row encode failed for field '{field_name}': {detail}",
763 ))
764 }
765
766 pub(crate) fn bytes_field_value_encode_failed(detail: impl fmt::Display) -> Self {
768 Self::serialize_internal(format!("bytes(field) value encode failed: {detail}"))
769 }
770
771 pub(crate) fn migration_state_serialize_failed(err: impl fmt::Display) -> Self {
773 Self::serialize_internal(format!("failed to serialize migration state: {err}"))
774 }
775
776 #[cold]
778 #[inline(never)]
779 pub(crate) fn store_corruption(message: impl Into<String>) -> Self {
780 Self::new(ErrorClass::Corruption, ErrorOrigin::Store, message.into())
781 }
782
783 pub(crate) fn multiple_commit_memory_ids_registered(ids: impl fmt::Debug) -> Self {
785 Self::store_corruption(format!(
786 "multiple commit marker memory ids registered: {ids:?}"
787 ))
788 }
789
790 pub(crate) fn migration_persisted_step_index_invalid_usize(
792 id: &str,
793 version: u64,
794 step_index: u64,
795 ) -> Self {
796 Self::store_corruption(format!(
797 "migration '{id}@{version}' persisted step index does not fit runtime usize: {step_index}",
798 ))
799 }
800
801 pub(crate) fn migration_persisted_step_index_out_of_bounds(
803 id: &str,
804 version: u64,
805 step_index: usize,
806 total_steps: usize,
807 ) -> Self {
808 Self::store_corruption(format!(
809 "migration '{id}@{version}' persisted step index out of bounds: {step_index} > {total_steps}",
810 ))
811 }
812
813 pub(crate) fn commit_corruption(detail: impl fmt::Display) -> Self {
815 Self::store_corruption(format!("commit marker corrupted: {detail}"))
816 }
817
818 pub(crate) fn commit_component_corruption(component: &str, detail: impl fmt::Display) -> Self {
820 Self::store_corruption(format!("commit marker {component} corrupted: {detail}"))
821 }
822
823 pub(crate) fn commit_id_generation_failed(detail: impl fmt::Display) -> Self {
825 Self::store_internal(format!("commit id generation failed: {detail}"))
826 }
827
828 pub(crate) fn commit_marker_payload_exceeds_u32_length_limit(label: &str, len: usize) -> Self {
830 Self::store_unsupported(format!("{label} exceeds u32 length limit: {len} bytes"))
831 }
832
833 pub(crate) fn commit_component_length_invalid(
835 component: &str,
836 len: usize,
837 expected: impl fmt::Display,
838 ) -> Self {
839 Self::commit_component_corruption(
840 component,
841 format!("invalid length {len}, expected {expected}"),
842 )
843 }
844
845 pub(crate) fn commit_marker_exceeds_max_size(size: usize, max_size: u32) -> Self {
847 Self::commit_corruption(format!(
848 "commit marker exceeds max size: {size} bytes (limit {max_size})",
849 ))
850 }
851
852 #[cfg(test)]
854 pub(crate) fn commit_marker_exceeds_max_size_before_persist(
855 size: usize,
856 max_size: u32,
857 ) -> Self {
858 Self::store_unsupported(format!(
859 "commit marker exceeds max size: {size} bytes (limit {max_size})",
860 ))
861 }
862
863 pub(crate) fn commit_control_slot_exceeds_max_size(size: usize, max_size: u32) -> Self {
865 Self::store_unsupported(format!(
866 "commit control slot exceeds max size: {size} bytes (limit {max_size})",
867 ))
868 }
869
870 pub(crate) fn commit_control_slot_marker_bytes_exceed_u32_length_limit(size: usize) -> Self {
872 Self::store_unsupported(format!(
873 "commit marker bytes exceed u32 length limit: {size} bytes",
874 ))
875 }
876
877 pub(crate) fn commit_control_slot_migration_bytes_exceed_u32_length_limit(size: usize) -> Self {
879 Self::store_unsupported(format!(
880 "commit migration bytes exceed u32 length limit: {size} bytes",
881 ))
882 }
883
884 pub(crate) fn startup_index_rebuild_invalid_data_key(
886 store_path: &str,
887 detail: impl fmt::Display,
888 ) -> Self {
889 Self::store_corruption(format!(
890 "startup index rebuild failed: invalid data key in store '{store_path}' ({detail})",
891 ))
892 }
893
894 #[cold]
896 #[inline(never)]
897 pub(crate) fn index_corruption(message: impl Into<String>) -> Self {
898 Self::new(ErrorClass::Corruption, ErrorOrigin::Index, message.into())
899 }
900
901 pub(crate) fn index_unique_validation_corruption(
903 entity_path: &str,
904 fields: &str,
905 detail: impl fmt::Display,
906 ) -> Self {
907 Self::index_plan_index_corruption(format!(
908 "index corrupted: {entity_path} ({fields}) -> {detail}",
909 ))
910 }
911
912 pub(crate) fn structural_index_entry_corruption(
914 entity_path: &str,
915 fields: &str,
916 detail: impl fmt::Display,
917 ) -> Self {
918 Self::index_plan_index_corruption(format!(
919 "index corrupted: {entity_path} ({fields}) -> {detail}",
920 ))
921 }
922
923 pub(crate) fn index_unique_validation_entity_key_required() -> Self {
925 Self::index_invariant("missing entity key during unique validation")
926 }
927
928 pub(crate) fn index_unique_validation_row_deserialize_failed(
930 data_key: impl fmt::Display,
931 source: impl fmt::Display,
932 ) -> Self {
933 Self::index_plan_serialize_corruption(format!(
934 "failed to structurally deserialize row: {data_key} ({source})"
935 ))
936 }
937
938 pub(crate) fn index_unique_validation_primary_key_decode_failed(
940 data_key: impl fmt::Display,
941 source: impl fmt::Display,
942 ) -> Self {
943 Self::index_plan_serialize_corruption(format!(
944 "failed to decode structural primary-key slot: {data_key} ({source})"
945 ))
946 }
947
948 pub(crate) fn index_unique_validation_key_rebuild_failed(
950 data_key: impl fmt::Display,
951 entity_path: &str,
952 source: impl fmt::Display,
953 ) -> Self {
954 Self::index_plan_serialize_corruption(format!(
955 "failed to structurally decode unique key row {data_key} for {entity_path}: {source}",
956 ))
957 }
958
959 pub(crate) fn index_unique_validation_row_required(data_key: impl fmt::Display) -> Self {
961 Self::index_plan_store_corruption(format!("missing row: {data_key}"))
962 }
963
964 pub(crate) fn index_predicate_parse_failed(
966 entity_path: &str,
967 index_name: &str,
968 predicate_sql: &str,
969 err: impl fmt::Display,
970 ) -> Self {
971 Self::index_invariant(format!(
972 "index predicate parse failed: {entity_path} ({index_name}) WHERE {predicate_sql} -> {err}",
973 ))
974 }
975
976 pub(crate) fn index_only_predicate_component_required() -> Self {
978 Self::index_invariant("index-only predicate program referenced missing index component")
979 }
980
981 pub(crate) fn index_scan_continuation_anchor_within_envelope_required() -> Self {
983 Self::index_invariant(
984 "index-range continuation anchor is outside the requested range envelope",
985 )
986 }
987
988 pub(crate) fn index_scan_continuation_advancement_required() -> Self {
990 Self::index_invariant("index-range continuation scan did not advance beyond the anchor")
991 }
992
993 pub(crate) fn index_scan_key_corrupted_during(
995 context: &'static str,
996 err: impl fmt::Display,
997 ) -> Self {
998 Self::index_corruption(format!("index key corrupted during {context}: {err}"))
999 }
1000
1001 pub(crate) fn index_projection_component_required(
1003 index_name: &str,
1004 component_index: usize,
1005 ) -> Self {
1006 Self::index_invariant(format!(
1007 "index projection referenced missing component: index='{index_name}' component_index={component_index}",
1008 ))
1009 }
1010
1011 pub(crate) fn unique_index_entry_single_key_required() -> Self {
1013 Self::index_corruption("unique index entry contains an unexpected number of keys")
1014 }
1015
1016 pub(crate) fn index_entry_decode_failed(err: impl fmt::Display) -> Self {
1018 Self::index_corruption(err.to_string())
1019 }
1020
1021 pub(crate) fn serialize_corruption(message: impl Into<String>) -> Self {
1023 Self::new(
1024 ErrorClass::Corruption,
1025 ErrorOrigin::Serialize,
1026 message.into(),
1027 )
1028 }
1029
1030 pub(crate) fn persisted_row_decode_failed(detail: impl fmt::Display) -> Self {
1032 Self::serialize_corruption(format!("row decode: {detail}"))
1033 }
1034
1035 pub(crate) fn persisted_row_field_decode_failed(
1037 field_name: &str,
1038 detail: impl fmt::Display,
1039 ) -> Self {
1040 Self::serialize_corruption(format!(
1041 "row decode failed for field '{field_name}': {detail}",
1042 ))
1043 }
1044
1045 pub(crate) fn persisted_row_field_kind_decode_failed(
1047 field_name: &str,
1048 field_kind: impl fmt::Debug,
1049 detail: impl fmt::Display,
1050 ) -> Self {
1051 Self::persisted_row_field_decode_failed(
1052 field_name,
1053 format!("kind={field_kind:?}: {detail}"),
1054 )
1055 }
1056
1057 pub(crate) fn persisted_row_field_payload_exact_len_required(
1059 field_name: &str,
1060 payload_kind: &str,
1061 expected_len: usize,
1062 ) -> Self {
1063 let unit = if expected_len == 1 { "byte" } else { "bytes" };
1064
1065 Self::persisted_row_field_decode_failed(
1066 field_name,
1067 format!("{payload_kind} payload must be exactly {expected_len} {unit}"),
1068 )
1069 }
1070
1071 pub(crate) fn persisted_row_field_payload_must_be_empty(
1073 field_name: &str,
1074 payload_kind: &str,
1075 ) -> Self {
1076 Self::persisted_row_field_decode_failed(
1077 field_name,
1078 format!("{payload_kind} payload must be empty"),
1079 )
1080 }
1081
1082 pub(crate) fn persisted_row_field_payload_invalid_byte(
1084 field_name: &str,
1085 payload_kind: &str,
1086 value: u8,
1087 ) -> Self {
1088 Self::persisted_row_field_decode_failed(
1089 field_name,
1090 format!("invalid {payload_kind} payload byte {value}"),
1091 )
1092 }
1093
1094 pub(crate) fn persisted_row_field_payload_non_finite(
1096 field_name: &str,
1097 payload_kind: &str,
1098 ) -> Self {
1099 Self::persisted_row_field_decode_failed(
1100 field_name,
1101 format!("{payload_kind} payload is non-finite"),
1102 )
1103 }
1104
1105 pub(crate) fn persisted_row_field_payload_out_of_range(
1107 field_name: &str,
1108 payload_kind: &str,
1109 ) -> Self {
1110 Self::persisted_row_field_decode_failed(
1111 field_name,
1112 format!("{payload_kind} payload out of range for target type"),
1113 )
1114 }
1115
1116 pub(crate) fn persisted_row_field_text_payload_invalid_utf8(
1118 field_name: &str,
1119 detail: impl fmt::Display,
1120 ) -> Self {
1121 Self::persisted_row_field_decode_failed(
1122 field_name,
1123 format!("invalid UTF-8 text payload ({detail})"),
1124 )
1125 }
1126
1127 pub(crate) fn persisted_row_slot_lookup_out_of_bounds(model_path: &str, slot: usize) -> Self {
1129 Self::index_invariant(format!(
1130 "slot lookup outside model bounds during structural row access: model='{model_path}' slot={slot}",
1131 ))
1132 }
1133
1134 pub(crate) fn persisted_row_slot_cache_lookup_out_of_bounds(
1136 model_path: &str,
1137 slot: usize,
1138 ) -> Self {
1139 Self::index_invariant(format!(
1140 "slot cache lookup outside model bounds during structural row access: model='{model_path}' slot={slot}",
1141 ))
1142 }
1143
1144 pub(crate) fn persisted_row_primary_key_field_missing(model_path: &str) -> Self {
1146 Self::index_invariant(format!(
1147 "entity primary key field missing during structural row validation: {model_path}",
1148 ))
1149 }
1150
1151 pub(crate) fn persisted_row_primary_key_not_storage_encodable(
1153 data_key: impl fmt::Display,
1154 detail: impl fmt::Display,
1155 ) -> Self {
1156 Self::persisted_row_decode_failed(format!(
1157 "primary-key value is not storage-key encodable: {data_key} ({detail})",
1158 ))
1159 }
1160
1161 pub(crate) fn persisted_row_primary_key_slot_missing(data_key: impl fmt::Display) -> Self {
1163 Self::persisted_row_decode_failed(format!(
1164 "missing primary-key slot while validating {data_key}",
1165 ))
1166 }
1167
1168 pub(crate) fn persisted_row_key_mismatch(
1170 expected_key: impl fmt::Display,
1171 found_key: impl fmt::Display,
1172 ) -> Self {
1173 Self::store_corruption(format!(
1174 "row key mismatch: expected {expected_key}, found {found_key}",
1175 ))
1176 }
1177
1178 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 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 pub(crate) fn data_key_primary_key_decode_failed(value: impl fmt::Debug) -> Self {
1195 Self::store_corruption(format!("data key primary key decode failed: {value:?}",))
1196 }
1197
1198 pub(crate) fn reverse_index_ordinal_overflow(
1200 source_path: &str,
1201 field_name: &str,
1202 target_path: &str,
1203 detail: impl fmt::Display,
1204 ) -> Self {
1205 Self::index_internal(format!(
1206 "reverse index ordinal overflow: source={source_path} field={field_name} target={target_path} ({detail})",
1207 ))
1208 }
1209
1210 pub(crate) fn reverse_index_entry_corrupted(
1212 source_path: &str,
1213 field_name: &str,
1214 target_path: &str,
1215 index_key: impl fmt::Debug,
1216 detail: impl fmt::Display,
1217 ) -> Self {
1218 Self::index_corruption(format!(
1219 "reverse index entry corrupted: source={source_path} field={field_name} target={target_path} key={index_key:?} ({detail})",
1220 ))
1221 }
1222
1223 pub(crate) fn reverse_index_entry_encode_failed(
1225 source_path: &str,
1226 field_name: &str,
1227 target_path: &str,
1228 detail: impl fmt::Display,
1229 ) -> Self {
1230 Self::index_unsupported(format!(
1231 "reverse index entry encoding failed: source={source_path} field={field_name} target={target_path} ({detail})",
1232 ))
1233 }
1234
1235 pub(crate) fn relation_target_store_missing(
1237 source_path: &str,
1238 field_name: &str,
1239 target_path: &str,
1240 store_path: &str,
1241 detail: impl fmt::Display,
1242 ) -> Self {
1243 Self::executor_internal(format!(
1244 "relation target store missing: source={source_path} field={field_name} target={target_path} store={store_path} ({detail})",
1245 ))
1246 }
1247
1248 pub(crate) fn relation_target_key_decode_failed(
1250 context_label: &str,
1251 source_path: &str,
1252 field_name: &str,
1253 target_path: &str,
1254 detail: impl fmt::Display,
1255 ) -> Self {
1256 Self::identity_corruption(format!(
1257 "{context_label}: source={source_path} field={field_name} target={target_path} ({detail})",
1258 ))
1259 }
1260
1261 pub(crate) fn relation_target_entity_mismatch(
1263 context_label: &str,
1264 source_path: &str,
1265 field_name: &str,
1266 target_path: &str,
1267 target_entity_name: &str,
1268 expected_tag: impl fmt::Display,
1269 actual_tag: impl fmt::Display,
1270 ) -> Self {
1271 Self::store_corruption(format!(
1272 "{context_label}: source={source_path} field={field_name} target={target_path} expected={target_entity_name} (tag={expected_tag}) actual_tag={actual_tag}",
1273 ))
1274 }
1275
1276 pub(crate) fn relation_source_row_decode_failed(
1278 source_path: &str,
1279 field_name: &str,
1280 target_path: &str,
1281 detail: impl fmt::Display,
1282 ) -> Self {
1283 Self::serialize_corruption(format!(
1284 "relation source row decode: source={source_path} field={field_name} target={target_path} ({detail})",
1285 ))
1286 }
1287
1288 pub(crate) fn relation_source_row_unsupported_scalar_relation_key(
1290 source_path: &str,
1291 field_name: &str,
1292 target_path: &str,
1293 ) -> Self {
1294 Self::serialize_corruption(format!(
1295 "relation source row decode: unsupported scalar relation key: source={source_path} field={field_name} target={target_path}",
1296 ))
1297 }
1298
1299 pub(crate) fn relation_source_row_invalid_field_kind(field_kind: impl fmt::Debug) -> Self {
1301 Self::serialize_corruption(format!(
1302 "invalid strong relation field kind during structural decode: {field_kind:?}"
1303 ))
1304 }
1305
1306 pub(crate) fn relation_source_row_unsupported_key_kind(field_kind: impl fmt::Debug) -> Self {
1308 Self::serialize_corruption(format!(
1309 "unsupported strong relation key kind during structural decode: {field_kind:?}"
1310 ))
1311 }
1312
1313 pub(crate) fn reverse_index_relation_target_decode_invariant_violated(
1315 source_path: &str,
1316 field_name: &str,
1317 target_path: &str,
1318 ) -> Self {
1319 Self::executor_internal(format!(
1320 "relation target decode invariant violated while preparing reverse index: source={source_path} field={field_name} target={target_path}",
1321 ))
1322 }
1323
1324 pub(crate) fn bytes_covering_component_payload_empty() -> Self {
1326 Self::index_corruption("index component payload is empty during covering projection decode")
1327 }
1328
1329 pub(crate) fn bytes_covering_bool_payload_truncated() -> Self {
1331 Self::index_corruption("bool covering component payload is truncated")
1332 }
1333
1334 pub(crate) fn bytes_covering_component_payload_invalid_length(payload_kind: &str) -> Self {
1336 Self::index_corruption(format!(
1337 "{payload_kind} covering component payload has invalid length"
1338 ))
1339 }
1340
1341 pub(crate) fn bytes_covering_bool_payload_invalid_value() -> Self {
1343 Self::index_corruption("bool covering component payload has invalid value")
1344 }
1345
1346 pub(crate) fn bytes_covering_text_payload_invalid_terminator() -> Self {
1348 Self::index_corruption("text covering component payload has invalid terminator")
1349 }
1350
1351 pub(crate) fn bytes_covering_text_payload_trailing_bytes() -> Self {
1353 Self::index_corruption("text covering component payload contains trailing bytes")
1354 }
1355
1356 pub(crate) fn bytes_covering_text_payload_invalid_utf8() -> Self {
1358 Self::index_corruption("text covering component payload is not valid UTF-8")
1359 }
1360
1361 pub(crate) fn bytes_covering_text_payload_invalid_escape_byte() -> Self {
1363 Self::index_corruption("text covering component payload has invalid escape byte")
1364 }
1365
1366 pub(crate) fn bytes_covering_text_payload_missing_terminator() -> Self {
1368 Self::index_corruption("text covering component payload is missing terminator")
1369 }
1370
1371 #[must_use]
1373 pub fn missing_persisted_slot(field_name: &'static str) -> Self {
1374 Self::serialize_corruption(format!("row decode: missing required field '{field_name}'",))
1375 }
1376
1377 pub(crate) fn identity_corruption(message: impl Into<String>) -> Self {
1379 Self::new(
1380 ErrorClass::Corruption,
1381 ErrorOrigin::Identity,
1382 message.into(),
1383 )
1384 }
1385
1386 #[cold]
1388 #[inline(never)]
1389 pub(crate) fn store_unsupported(message: impl Into<String>) -> Self {
1390 Self::new(ErrorClass::Unsupported, ErrorOrigin::Store, message.into())
1391 }
1392
1393 pub(crate) fn migration_label_empty(label: &str) -> Self {
1395 Self::store_unsupported(format!("{label} cannot be empty"))
1396 }
1397
1398 pub(crate) fn migration_step_row_ops_required(name: &str) -> Self {
1400 Self::store_unsupported(format!(
1401 "migration step '{name}' must include at least one row op",
1402 ))
1403 }
1404
1405 pub(crate) fn migration_plan_version_required(id: &str) -> Self {
1407 Self::store_unsupported(format!("migration plan '{id}' version must be > 0",))
1408 }
1409
1410 pub(crate) fn migration_plan_steps_required(id: &str) -> Self {
1412 Self::store_unsupported(format!(
1413 "migration plan '{id}' must include at least one step",
1414 ))
1415 }
1416
1417 pub(crate) fn migration_cursor_out_of_bounds(
1419 id: &str,
1420 version: u64,
1421 next_step: usize,
1422 total_steps: usize,
1423 ) -> Self {
1424 Self::store_unsupported(format!(
1425 "migration '{id}@{version}' cursor out of bounds: next_step={next_step} total_steps={total_steps}",
1426 ))
1427 }
1428
1429 pub(crate) fn migration_execution_requires_max_steps(id: &str) -> Self {
1431 Self::store_unsupported(format!("migration '{id}' execution requires max_steps > 0",))
1432 }
1433
1434 pub(crate) fn migration_in_progress_conflict(
1436 requested_id: &str,
1437 requested_version: u64,
1438 active_id: &str,
1439 active_version: u64,
1440 ) -> Self {
1441 Self::store_unsupported(format!(
1442 "migration '{requested_id}@{requested_version}' cannot execute while migration '{active_id}@{active_version}' is in progress",
1443 ))
1444 }
1445
1446 pub(crate) fn unsupported_entity_tag_in_data_store(
1448 entity_tag: crate::types::EntityTag,
1449 ) -> Self {
1450 Self::store_unsupported(format!(
1451 "unsupported entity tag in data store: '{}'",
1452 entity_tag.value()
1453 ))
1454 }
1455
1456 pub(crate) fn configured_commit_memory_id_mismatch(
1458 configured_id: u8,
1459 registered_id: u8,
1460 ) -> Self {
1461 Self::store_unsupported(format!(
1462 "configured commit memory id {configured_id} does not match existing commit marker id {registered_id}",
1463 ))
1464 }
1465
1466 pub(crate) fn commit_memory_id_already_registered(memory_id: u8, label: &str) -> Self {
1468 Self::store_unsupported(format!(
1469 "configured commit memory id {memory_id} is already registered as '{label}'",
1470 ))
1471 }
1472
1473 pub(crate) fn commit_memory_id_outside_reserved_ranges(memory_id: u8) -> Self {
1475 Self::store_unsupported(format!(
1476 "configured commit memory id {memory_id} is outside reserved ranges",
1477 ))
1478 }
1479
1480 pub(crate) fn commit_memory_id_registration_failed(err: impl fmt::Display) -> Self {
1482 Self::store_internal(format!("commit memory id registration failed: {err}"))
1483 }
1484
1485 pub(crate) fn index_unsupported(message: impl Into<String>) -> Self {
1487 Self::new(ErrorClass::Unsupported, ErrorOrigin::Index, message.into())
1488 }
1489
1490 pub(crate) fn index_component_exceeds_max_size(
1492 key_item: impl fmt::Display,
1493 len: usize,
1494 max_component_size: usize,
1495 ) -> Self {
1496 Self::index_unsupported(format!(
1497 "index component exceeds max size: key item '{key_item}' -> {len} bytes (limit {max_component_size})",
1498 ))
1499 }
1500
1501 pub(crate) fn index_entry_exceeds_max_keys(
1503 entity_path: &str,
1504 fields: &str,
1505 keys: usize,
1506 ) -> Self {
1507 Self::index_unsupported(format!(
1508 "index entry exceeds max keys: {entity_path} ({fields}) -> {keys} keys",
1509 ))
1510 }
1511
1512 #[cfg(test)]
1514 pub(crate) fn index_entry_duplicate_keys_unexpected(entity_path: &str, fields: &str) -> Self {
1515 Self::index_invariant(format!(
1516 "index entry unexpectedly contains duplicate keys: {entity_path} ({fields})",
1517 ))
1518 }
1519
1520 pub(crate) fn index_entry_key_encoding_failed(
1522 entity_path: &str,
1523 fields: &str,
1524 err: impl fmt::Display,
1525 ) -> Self {
1526 Self::index_unsupported(format!(
1527 "index entry key encoding failed: {entity_path} ({fields}) -> {err}",
1528 ))
1529 }
1530
1531 pub(crate) fn serialize_unsupported(message: impl Into<String>) -> Self {
1533 Self::new(
1534 ErrorClass::Unsupported,
1535 ErrorOrigin::Serialize,
1536 message.into(),
1537 )
1538 }
1539
1540 pub(crate) fn cursor_unsupported(message: impl Into<String>) -> Self {
1542 Self::new(ErrorClass::Unsupported, ErrorOrigin::Cursor, message.into())
1543 }
1544
1545 pub(crate) fn serialize_incompatible_persisted_format(message: impl Into<String>) -> Self {
1547 Self::new(
1548 ErrorClass::IncompatiblePersistedFormat,
1549 ErrorOrigin::Serialize,
1550 message.into(),
1551 )
1552 }
1553
1554 pub(crate) fn serialize_payload_decode_failed(
1557 source: SerializeError,
1558 payload_label: &'static str,
1559 ) -> Self {
1560 match source {
1561 SerializeError::DeserializeSizeLimitExceeded { len, max_bytes } => {
1564 Self::serialize_corruption(format!(
1565 "{payload_label} decode failed: payload size {len} exceeds limit {max_bytes}"
1566 ))
1567 }
1568 SerializeError::Deserialize(_) => Self::serialize_corruption(format!(
1569 "{payload_label} decode failed: {}",
1570 SerializeErrorKind::Deserialize
1571 )),
1572 SerializeError::Serialize(_) => Self::serialize_corruption(format!(
1573 "{payload_label} decode failed: {}",
1574 SerializeErrorKind::Serialize
1575 )),
1576 }
1577 }
1578
1579 #[cfg(feature = "sql")]
1582 pub(crate) fn query_unsupported_sql_feature(feature: &'static str) -> Self {
1583 let message = format!(
1584 "SQL query is not executable in this release: unsupported SQL feature: {feature}"
1585 );
1586
1587 Self {
1588 class: ErrorClass::Unsupported,
1589 origin: ErrorOrigin::Query,
1590 message,
1591 detail: Some(ErrorDetail::Query(
1592 QueryErrorDetail::UnsupportedSqlFeature { feature },
1593 )),
1594 }
1595 }
1596
1597 pub fn store_not_found(key: impl Into<String>) -> Self {
1598 let key = key.into();
1599
1600 Self {
1601 class: ErrorClass::NotFound,
1602 origin: ErrorOrigin::Store,
1603 message: format!("data key not found: {key}"),
1604 detail: Some(ErrorDetail::Store(StoreError::NotFound { key })),
1605 }
1606 }
1607
1608 pub fn unsupported_entity_path(path: impl Into<String>) -> Self {
1610 let path = path.into();
1611
1612 Self::new(
1613 ErrorClass::Unsupported,
1614 ErrorOrigin::Store,
1615 format!("unsupported entity path: '{path}'"),
1616 )
1617 }
1618
1619 #[must_use]
1620 pub const fn is_not_found(&self) -> bool {
1621 matches!(
1622 self.detail,
1623 Some(ErrorDetail::Store(StoreError::NotFound { .. }))
1624 )
1625 }
1626
1627 #[must_use]
1628 pub fn display_with_class(&self) -> String {
1629 format!("{}:{}: {}", self.origin, self.class, self.message)
1630 }
1631
1632 #[cold]
1634 #[inline(never)]
1635 pub(crate) fn index_plan_corruption(origin: ErrorOrigin, message: impl Into<String>) -> Self {
1636 let message = message.into();
1637 Self::new(
1638 ErrorClass::Corruption,
1639 origin,
1640 format!("corruption detected ({origin}): {message}"),
1641 )
1642 }
1643
1644 #[cold]
1646 #[inline(never)]
1647 pub(crate) fn index_plan_index_corruption(message: impl Into<String>) -> Self {
1648 Self::index_plan_corruption(ErrorOrigin::Index, message)
1649 }
1650
1651 #[cold]
1653 #[inline(never)]
1654 pub(crate) fn index_plan_store_corruption(message: impl Into<String>) -> Self {
1655 Self::index_plan_corruption(ErrorOrigin::Store, message)
1656 }
1657
1658 #[cold]
1660 #[inline(never)]
1661 pub(crate) fn index_plan_serialize_corruption(message: impl Into<String>) -> Self {
1662 Self::index_plan_corruption(ErrorOrigin::Serialize, message)
1663 }
1664
1665 #[cfg(test)]
1667 pub(crate) fn index_plan_invariant(origin: ErrorOrigin, message: impl Into<String>) -> Self {
1668 let message = message.into();
1669 Self::new(
1670 ErrorClass::InvariantViolation,
1671 origin,
1672 format!("invariant violation detected ({origin}): {message}"),
1673 )
1674 }
1675
1676 #[cfg(test)]
1678 pub(crate) fn index_plan_store_invariant(message: impl Into<String>) -> Self {
1679 Self::index_plan_invariant(ErrorOrigin::Store, message)
1680 }
1681
1682 pub(crate) fn index_violation(path: &str, index_fields: &[&str]) -> Self {
1684 Self::new(
1685 ErrorClass::Conflict,
1686 ErrorOrigin::Index,
1687 format!(
1688 "index constraint violation: {path} ({})",
1689 index_fields.join(", ")
1690 ),
1691 )
1692 }
1693}
1694
1695#[derive(Debug, ThisError)]
1703pub enum ErrorDetail {
1704 #[error("{0}")]
1705 Store(StoreError),
1706 #[error("{0}")]
1707 Query(QueryErrorDetail),
1708 }
1715
1716#[derive(Debug, ThisError)]
1724pub enum StoreError {
1725 #[error("key not found: {key}")]
1726 NotFound { key: String },
1727
1728 #[error("store corruption: {message}")]
1729 Corrupt { message: String },
1730
1731 #[error("store invariant violation: {message}")]
1732 InvariantViolation { message: String },
1733}
1734
1735#[derive(Debug, ThisError)]
1742pub enum QueryErrorDetail {
1743 #[error("unsupported SQL feature: {feature}")]
1744 UnsupportedSqlFeature { feature: &'static str },
1745}
1746
1747#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1754pub enum ErrorClass {
1755 Corruption,
1756 IncompatiblePersistedFormat,
1757 NotFound,
1758 Internal,
1759 Conflict,
1760 Unsupported,
1761 InvariantViolation,
1762}
1763
1764impl fmt::Display for ErrorClass {
1765 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1766 let label = match self {
1767 Self::Corruption => "corruption",
1768 Self::IncompatiblePersistedFormat => "incompatible_persisted_format",
1769 Self::NotFound => "not_found",
1770 Self::Internal => "internal",
1771 Self::Conflict => "conflict",
1772 Self::Unsupported => "unsupported",
1773 Self::InvariantViolation => "invariant_violation",
1774 };
1775 write!(f, "{label}")
1776 }
1777}
1778
1779#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1786pub enum ErrorOrigin {
1787 Serialize,
1788 Store,
1789 Index,
1790 Identity,
1791 Query,
1792 Planner,
1793 Cursor,
1794 Recovery,
1795 Response,
1796 Executor,
1797 Interface,
1798}
1799
1800impl fmt::Display for ErrorOrigin {
1801 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1802 let label = match self {
1803 Self::Serialize => "serialize",
1804 Self::Store => "store",
1805 Self::Index => "index",
1806 Self::Identity => "identity",
1807 Self::Query => "query",
1808 Self::Planner => "planner",
1809 Self::Cursor => "cursor",
1810 Self::Recovery => "recovery",
1811 Self::Response => "response",
1812 Self::Executor => "executor",
1813 Self::Interface => "interface",
1814 };
1815 write!(f, "{label}")
1816 }
1817}