1#[cfg(test)]
9mod tests;
10
11use icydb_diagnostic_code as diagnostic_code;
12use std::fmt;
13
14pub(crate) const COMPACT_QUERY_DIAGNOSTIC_MESSAGE: &str = "query diagnostic";
15const COMPACT_RUNTIME_DIAGNOSTIC_MESSAGE: &str = "runtime diagnostic";
16const COMPACT_STORE_DIAGNOSTIC_MESSAGE: &str = "store diagnostic";
17const COMPACT_INDEX_DIAGNOSTIC_MESSAGE: &str = "index diagnostic";
18const COMPACT_SERIALIZE_DIAGNOSTIC_MESSAGE: &str = "serialize diagnostic";
19const COMPACT_IDENTITY_DIAGNOSTIC_MESSAGE: &str = "identity diagnostic";
20
21const fn compact_message_for(_class: ErrorClass, origin: ErrorOrigin) -> &'static str {
22 match origin {
23 ErrorOrigin::Serialize => COMPACT_SERIALIZE_DIAGNOSTIC_MESSAGE,
24 ErrorOrigin::Store => COMPACT_STORE_DIAGNOSTIC_MESSAGE,
25 ErrorOrigin::Index => COMPACT_INDEX_DIAGNOSTIC_MESSAGE,
26 ErrorOrigin::Identity => COMPACT_IDENTITY_DIAGNOSTIC_MESSAGE,
27 ErrorOrigin::Query | ErrorOrigin::Planner | ErrorOrigin::Response => {
28 COMPACT_QUERY_DIAGNOSTIC_MESSAGE
29 }
30 ErrorOrigin::Cursor
31 | ErrorOrigin::Recovery
32 | ErrorOrigin::Executor
33 | ErrorOrigin::Interface => COMPACT_RUNTIME_DIAGNOSTIC_MESSAGE,
34 }
35}
36
37pub struct InternalError {
138 pub(crate) class: ErrorClass,
139 pub(crate) origin: ErrorOrigin,
140
141 pub(crate) detail: Option<ErrorDetail>,
144}
145
146#[expect(
147 clippy::missing_const_for_fn,
148 reason = "internal error constructors stay non-const so compact diagnostic construction does not force const churn across subsystem helper seams"
149)]
150impl InternalError {
151 #[must_use]
155 #[cold]
156 #[inline(never)]
157 pub fn new(class: ErrorClass, origin: ErrorOrigin) -> Self {
158 let detail = match (class, origin) {
159 (ErrorClass::Corruption, ErrorOrigin::Store) => {
160 Some(ErrorDetail::Store(StoreError::Corrupt))
161 }
162 (ErrorClass::InvariantViolation, ErrorOrigin::Store) => {
163 Some(ErrorDetail::Store(StoreError::InvariantViolation))
164 }
165 _ => None,
166 };
167
168 Self {
169 class,
170 origin,
171 detail,
172 }
173 }
174
175 #[must_use]
177 pub const fn class(&self) -> ErrorClass {
178 self.class
179 }
180
181 #[must_use]
183 pub const fn origin(&self) -> ErrorOrigin {
184 self.origin
185 }
186
187 #[must_use]
189 pub const fn message(&self) -> &'static str {
190 compact_message_for(self.class, self.origin)
191 }
192
193 #[must_use]
195 pub const fn detail(&self) -> Option<&ErrorDetail> {
196 self.detail.as_ref()
197 }
198
199 #[must_use]
201 pub fn diagnostic(&self) -> diagnostic_code::Diagnostic {
202 diagnostic_code::Diagnostic::new(
203 self.diagnostic_code(),
204 self.origin.diagnostic_origin(),
205 self.detail
206 .as_ref()
207 .and_then(ErrorDetail::diagnostic_detail),
208 )
209 }
210
211 #[must_use]
213 pub fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
214 self.detail.as_ref().map_or_else(
215 || self.class.diagnostic_code(self.origin),
216 ErrorDetail::diagnostic_code,
217 )
218 }
219
220 #[must_use]
222 pub fn into_message(self) -> String {
223 self.message().to_string()
224 }
225
226 #[cold]
228 #[inline(never)]
229 pub(crate) fn classified(class: ErrorClass, origin: ErrorOrigin) -> Self {
230 Self::new(class, origin)
231 }
232
233 #[cold]
237 #[inline(never)]
238 pub(crate) fn with_origin(self, origin: ErrorOrigin) -> Self {
239 Self::classified(self.class, origin)
240 }
241
242 #[cold]
244 #[inline(never)]
245 pub(crate) fn index_invariant() -> Self {
246 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Index)
247 }
248
249 pub(crate) fn index_key_field_count_exceeds_max(
251 _index_name: &str,
252 _field_count: usize,
253 _max_fields: usize,
254 ) -> Self {
255 Self::index_invariant()
256 }
257
258 pub(crate) fn index_key_item_field_missing_on_entity_model(_field: &str) -> Self {
260 Self::index_invariant()
261 }
262
263 pub(crate) fn index_key_item_field_missing_on_lookup_row(_field: &str) -> Self {
265 Self::index_invariant()
266 }
267
268 pub(crate) fn index_expression_source_type_mismatch(
270 _index_name: &str,
271 _expression: impl Sized,
272 _expected: impl Sized,
273 _source_label: &str,
274 ) -> Self {
275 Self::index_invariant()
276 }
277
278 #[cold]
281 #[inline(never)]
282 pub(crate) fn planner_executor_invariant() -> Self {
283 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Planner)
284 }
285
286 #[cold]
289 #[inline(never)]
290 pub(crate) fn query_executor_invariant() -> Self {
291 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Query)
292 }
293
294 #[cold]
297 #[inline(never)]
298 pub(crate) fn cursor_executor_invariant() -> Self {
299 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Cursor)
300 }
301
302 #[cold]
304 #[inline(never)]
305 pub(crate) fn executor_invariant() -> Self {
306 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Executor)
307 }
308
309 #[cold]
311 #[inline(never)]
312 pub(crate) fn executor_internal() -> Self {
313 Self::new(ErrorClass::Internal, ErrorOrigin::Executor)
314 }
315
316 #[cold]
318 #[inline(never)]
319 pub(crate) fn executor_unsupported() -> Self {
320 Self::new(ErrorClass::Unsupported, ErrorOrigin::Executor)
321 }
322
323 pub(crate) fn mutation_entity_primary_key_missing(
325 _entity_path: &str,
326 _field_name: &str,
327 ) -> Self {
328 Self::executor_invariant()
329 }
330
331 pub(crate) fn mutation_entity_primary_key_invalid_value(
333 _entity_path: &str,
334 _field_name: &str,
335 _value: &crate::value::Value,
336 ) -> Self {
337 Self::executor_invariant()
338 }
339
340 pub(crate) fn mutation_entity_primary_key_type_mismatch(
342 _entity_path: &str,
343 _field_name: &str,
344 _value: &crate::value::Value,
345 ) -> Self {
346 Self::executor_invariant()
347 }
348
349 pub(crate) fn mutation_entity_primary_key_mismatch(
351 _entity_path: &str,
352 _field_name: &str,
353 _field_value: &crate::value::Value,
354 _identity_key: &crate::value::Value,
355 ) -> Self {
356 Self::executor_invariant()
357 }
358
359 pub(crate) fn mutation_entity_field_missing(
361 _entity_path: &str,
362 _field_name: &str,
363 _indexed: bool,
364 ) -> Self {
365 Self::executor_invariant()
366 }
367
368 pub(crate) fn mutation_structural_patch_required_field_missing(
370 _entity_path: &str,
371 _field_name: &str,
372 ) -> Self {
373 Self::executor_invariant()
374 }
375
376 pub(crate) fn mutation_entity_field_type_mismatch(
378 _entity_path: &str,
379 _field_name: &str,
380 _value: &crate::value::Value,
381 ) -> Self {
382 Self::executor_invariant()
383 }
384
385 pub(crate) fn mutation_generated_field_explicit(_entity_path: &str, _field_name: &str) -> Self {
387 Self::executor_unsupported()
388 }
389
390 #[must_use]
392 pub fn mutation_create_missing_authored_fields(_entity_path: &str, _field_names: &str) -> Self {
393 Self::executor_unsupported()
394 }
395
396 pub(crate) fn mutation_structural_after_image_invalid(
401 _entity_path: &str,
402 _data_key: impl Sized,
403 _detail: impl Sized,
404 ) -> Self {
405 Self::executor_invariant()
406 }
407
408 pub(crate) fn mutation_structural_field_unknown(_entity_path: &str, _field_name: &str) -> Self {
410 Self::executor_invariant()
411 }
412
413 pub(crate) fn mutation_decimal_scale_mismatch(
415 _entity_path: &str,
416 _field_name: &str,
417 _expected_scale: impl Sized,
418 _actual_scale: impl Sized,
419 ) -> Self {
420 Self::executor_unsupported()
421 }
422
423 pub(crate) fn mutation_text_max_len_exceeded(
425 _entity_path: &str,
426 _field_name: &str,
427 _max_len: impl Sized,
428 _actual_len: impl Sized,
429 ) -> Self {
430 Self::executor_unsupported()
431 }
432
433 pub(crate) fn mutation_set_field_list_required(_entity_path: &str, _field_name: &str) -> Self {
435 Self::executor_invariant()
436 }
437
438 pub(crate) fn mutation_set_field_not_canonical(_entity_path: &str, _field_name: &str) -> Self {
440 Self::executor_invariant()
441 }
442
443 pub(crate) fn mutation_map_field_map_required(_entity_path: &str, _field_name: &str) -> Self {
445 Self::executor_invariant()
446 }
447
448 pub(crate) fn mutation_map_field_entries_invalid(
450 _entity_path: &str,
451 _field_name: &str,
452 _detail: impl Sized,
453 ) -> Self {
454 Self::executor_invariant()
455 }
456
457 pub(crate) fn mutation_map_field_entries_not_canonical(
459 _entity_path: &str,
460 _field_name: &str,
461 ) -> Self {
462 Self::executor_invariant()
463 }
464
465 pub(crate) fn scalar_page_ordering_after_filtering_required() -> Self {
467 Self::query_executor_invariant()
468 }
469
470 pub(crate) fn scalar_page_cursor_boundary_order_required() -> Self {
472 Self::query_executor_invariant()
473 }
474
475 pub(crate) fn scalar_page_cursor_boundary_after_ordering_required() -> Self {
477 Self::query_executor_invariant()
478 }
479
480 pub(crate) fn scalar_page_pagination_after_ordering_required() -> Self {
482 Self::query_executor_invariant()
483 }
484
485 pub(crate) fn scalar_page_delete_limit_after_ordering_required() -> Self {
487 Self::query_executor_invariant()
488 }
489
490 pub(crate) fn load_runtime_scalar_payload_required() -> Self {
492 Self::query_executor_invariant()
493 }
494
495 pub(crate) fn load_runtime_grouped_payload_required() -> Self {
497 Self::query_executor_invariant()
498 }
499
500 pub(crate) fn load_runtime_scalar_surface_payload_required() -> Self {
502 Self::query_executor_invariant()
503 }
504
505 pub(crate) fn load_runtime_grouped_surface_payload_required() -> Self {
507 Self::query_executor_invariant()
508 }
509
510 pub(crate) fn load_executor_load_plan_required() -> Self {
512 Self::query_executor_invariant()
513 }
514
515 pub(crate) fn delete_executor_grouped_unsupported() -> Self {
517 Self::executor_unsupported()
518 }
519
520 pub(crate) fn delete_executor_delete_plan_required() -> Self {
522 Self::query_executor_invariant()
523 }
524
525 pub(crate) fn aggregate_fold_mode_terminal_contract_required() -> Self {
527 Self::query_executor_invariant()
528 }
529
530 pub(crate) fn fast_stream_route_kind_request_match_required() -> Self {
532 Self::query_executor_invariant()
533 }
534
535 pub(crate) fn secondary_index_prefix_spec_required() -> Self {
537 Self::query_executor_invariant()
538 }
539
540 pub(crate) fn index_range_limit_spec_required() -> Self {
542 Self::query_executor_invariant()
543 }
544
545 pub(crate) fn mutation_atomic_save_duplicate_key(_entity_path: &str, _key: impl Sized) -> Self {
547 Self::executor_unsupported()
548 }
549
550 pub(crate) fn mutation_index_store_generation_changed(
552 _expected_generation: u64,
553 _observed_generation: u64,
554 ) -> Self {
555 Self::executor_invariant()
556 }
557
558 #[cold]
560 #[inline(never)]
561 pub(crate) fn planner_invariant() -> Self {
562 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Planner)
563 }
564
565 pub(crate) fn query_invalid_logical_plan() -> Self {
567 Self::planner_invariant()
568 }
569
570 pub(crate) fn store_invariant() -> Self {
572 Self::new(ErrorClass::InvariantViolation, ErrorOrigin::Store)
573 }
574
575 pub(crate) fn duplicate_runtime_hooks_for_entity_tag(
577 _entity_tag: crate::types::EntityTag,
578 ) -> Self {
579 Self::store_invariant()
580 }
581
582 pub(crate) fn duplicate_runtime_hooks_for_entity_path(_entity_path: &str) -> Self {
584 Self::store_invariant()
585 }
586
587 #[cold]
589 #[inline(never)]
590 pub(crate) fn store_internal() -> Self {
591 Self::new(ErrorClass::Internal, ErrorOrigin::Store)
592 }
593
594 pub(crate) fn commit_memory_id_unconfigured() -> Self {
596 Self::store_internal()
597 }
598
599 pub(crate) fn commit_memory_id_mismatch(_cached_id: u8, _configured_id: u8) -> Self {
601 Self::store_internal()
602 }
603
604 pub(crate) fn commit_memory_stable_key_mismatch(
606 _cached_key: &str,
607 _configured_key: &str,
608 ) -> Self {
609 Self::store_internal()
610 }
611
612 pub(crate) fn delete_rollback_row_required() -> Self {
614 Self::store_internal()
615 }
616
617 pub(crate) fn recovery_integrity_validation_failed(
619 _missing_index_entries: u64,
620 _divergent_index_entries: u64,
621 _orphan_index_references: u64,
622 ) -> Self {
623 Self::store_corruption()
624 }
625
626 #[cold]
628 #[inline(never)]
629 pub(crate) fn index_internal() -> Self {
630 Self::new(ErrorClass::Internal, ErrorOrigin::Index)
631 }
632
633 pub(crate) fn structural_index_removal_entity_key_required() -> Self {
635 Self::index_internal()
636 }
637
638 pub(crate) fn structural_index_insertion_entity_key_required() -> Self {
640 Self::index_internal()
641 }
642
643 pub(crate) fn index_commit_op_old_entity_key_required() -> Self {
645 Self::index_internal()
646 }
647
648 pub(crate) fn index_commit_op_new_entity_key_required() -> Self {
650 Self::index_internal()
651 }
652
653 #[cfg(test)]
655 pub(crate) fn query_internal() -> Self {
656 Self::new(ErrorClass::Internal, ErrorOrigin::Query)
657 }
658
659 #[cold]
661 #[inline(never)]
662 pub(crate) fn query_unsupported() -> Self {
663 Self::new(ErrorClass::Unsupported, ErrorOrigin::Query)
664 }
665
666 #[cold]
668 #[inline(never)]
669 #[cfg(feature = "sql")]
670 pub(crate) fn query_schema_ddl_admission(error: SchemaDdlAdmissionError) -> Self {
671 Self {
672 class: ErrorClass::Unsupported,
673 origin: ErrorOrigin::Query,
674 detail: Some(ErrorDetail::Query(QueryErrorDetail::SchemaDdlAdmission {
675 error,
676 })),
677 }
678 }
679
680 #[cold]
682 #[inline(never)]
683 pub(crate) fn query_numeric_overflow() -> Self {
684 Self {
685 class: ErrorClass::Unsupported,
686 origin: ErrorOrigin::Query,
687 detail: Some(ErrorDetail::Query(QueryErrorDetail::NumericOverflow)),
688 }
689 }
690
691 #[cold]
694 #[inline(never)]
695 pub(crate) fn query_numeric_not_representable() -> Self {
696 Self {
697 class: ErrorClass::Unsupported,
698 origin: ErrorOrigin::Query,
699 detail: Some(ErrorDetail::Query(
700 QueryErrorDetail::NumericNotRepresentable,
701 )),
702 }
703 }
704
705 #[cold]
707 #[inline(never)]
708 pub(crate) fn serialize_internal() -> Self {
709 Self::new(ErrorClass::Internal, ErrorOrigin::Serialize)
710 }
711
712 pub(crate) fn persisted_row_encode_failed(_detail: impl Sized) -> Self {
714 Self::persisted_row_encode_internal()
715 }
716
717 pub(crate) fn persisted_row_encode_internal() -> Self {
719 Self::serialize_internal()
720 }
721
722 pub(crate) fn persisted_row_field_encode_failed(field_name: &str, _detail: impl Sized) -> Self {
724 Self::persisted_row_field_encode_internal(field_name)
725 }
726
727 pub(crate) fn persisted_row_field_encode_internal(_field_name: &str) -> Self {
729 Self::persisted_row_encode_internal()
730 }
731
732 pub(crate) fn bytes_field_value_encode_failed(_detail: impl Sized) -> Self {
734 Self::serialize_internal()
735 }
736
737 #[cold]
739 #[inline(never)]
740 pub(crate) fn store_corruption() -> Self {
741 Self::new(ErrorClass::Corruption, ErrorOrigin::Store)
742 }
743
744 pub(crate) fn commit_corruption() -> Self {
746 Self::store_corruption()
747 }
748
749 pub(crate) fn commit_component_corruption() -> Self {
751 Self::commit_corruption()
752 }
753
754 pub(crate) fn commit_id_generation_failed() -> Self {
756 Self::store_internal()
757 }
758
759 pub(crate) fn commit_marker_payload_exceeds_u32_length_limit() -> Self {
761 Self::store_unsupported()
762 }
763
764 pub(crate) fn commit_component_length_invalid() -> Self {
766 Self::commit_corruption()
767 }
768
769 pub(crate) fn commit_marker_exceeds_max_size() -> Self {
771 Self::commit_corruption()
772 }
773
774 pub(crate) fn commit_control_slot_exceeds_max_size() -> Self {
776 Self::store_unsupported()
777 }
778
779 pub(crate) fn commit_control_slot_marker_bytes_exceed_u32_length_limit() -> Self {
781 Self::store_unsupported()
782 }
783
784 pub(crate) fn startup_index_rebuild_invalid_data_key() -> Self {
786 Self::store_corruption()
787 }
788
789 #[cold]
791 #[inline(never)]
792 pub(crate) fn index_corruption() -> Self {
793 Self::new(ErrorClass::Corruption, ErrorOrigin::Index)
794 }
795
796 pub(crate) fn index_unique_validation_corruption() -> Self {
798 Self::index_plan_index_corruption()
799 }
800
801 pub(crate) fn structural_index_entry_corruption() -> Self {
803 Self::index_plan_index_corruption()
804 }
805
806 pub(crate) fn index_unique_validation_entity_key_required() -> Self {
808 Self::index_invariant()
809 }
810
811 pub(crate) fn index_unique_validation_row_deserialize_failed() -> Self {
813 Self::index_plan_serialize_corruption()
814 }
815
816 pub(crate) fn index_unique_validation_primary_key_decode_failed() -> Self {
818 Self::index_plan_serialize_corruption()
819 }
820
821 pub(crate) fn index_unique_validation_key_rebuild_failed() -> Self {
823 Self::index_plan_serialize_corruption()
824 }
825
826 pub(crate) fn index_unique_validation_row_required() -> Self {
828 Self::index_plan_store_corruption()
829 }
830
831 pub(crate) fn index_only_predicate_component_required() -> Self {
833 Self::index_invariant()
834 }
835
836 pub(crate) fn index_scan_continuation_anchor_within_envelope_required() -> Self {
838 Self::index_invariant()
839 }
840
841 pub(crate) fn index_scan_continuation_advancement_required() -> Self {
843 Self::index_invariant()
844 }
845
846 pub(crate) fn index_scan_key_corrupted_during(
848 _context: &'static str,
849 _err: impl Sized,
850 ) -> Self {
851 Self::index_corruption()
852 }
853
854 pub(crate) fn index_projection_component_required(
856 _index_name: &str,
857 _component_index: usize,
858 ) -> Self {
859 Self::index_invariant()
860 }
861
862 pub(crate) fn index_entry_decode_failed() -> Self {
864 Self::index_corruption()
865 }
866
867 pub(crate) fn serialize_corruption() -> Self {
869 Self::new(ErrorClass::Corruption, ErrorOrigin::Serialize)
870 }
871
872 pub(crate) fn persisted_row_decode_failed(_detail: impl Sized) -> Self {
874 Self::persisted_row_decode_corruption()
875 }
876
877 pub(crate) fn persisted_row_decode_corruption() -> Self {
879 Self::serialize_corruption()
880 }
881
882 pub(crate) fn persisted_row_field_decode_failed(field_name: &str, _detail: impl Sized) -> Self {
884 Self::persisted_row_field_decode_corruption(field_name)
885 }
886
887 pub(crate) fn persisted_row_field_decode_corruption(_field_name: &str) -> Self {
889 Self::persisted_row_decode_corruption()
890 }
891
892 pub(crate) fn persisted_row_field_kind_decode_failed(
894 field_name: &str,
895 _field_kind: impl fmt::Debug,
896 _detail: impl Sized,
897 ) -> Self {
898 Self::persisted_row_field_decode_corruption(field_name)
899 }
900
901 pub(crate) fn persisted_row_field_payload_exact_len_required(field_name: &str) -> Self {
903 Self::persisted_row_field_decode_corruption(field_name)
904 }
905
906 pub(crate) fn persisted_row_field_payload_must_be_empty(field_name: &str) -> Self {
908 Self::persisted_row_field_decode_corruption(field_name)
909 }
910
911 pub(crate) fn persisted_row_field_payload_invalid_byte(field_name: &str) -> Self {
913 Self::persisted_row_field_decode_corruption(field_name)
914 }
915
916 pub(crate) fn persisted_row_field_payload_non_finite(field_name: &str) -> Self {
918 Self::persisted_row_field_decode_corruption(field_name)
919 }
920
921 pub(crate) fn persisted_row_field_payload_out_of_range(field_name: &str) -> Self {
923 Self::persisted_row_field_decode_corruption(field_name)
924 }
925
926 pub(crate) fn persisted_row_field_text_payload_invalid_utf8(field_name: &str) -> Self {
928 Self::persisted_row_field_decode_corruption(field_name)
929 }
930
931 pub(crate) fn persisted_row_slot_lookup_out_of_bounds(_model_path: &str, _slot: usize) -> Self {
933 Self::index_invariant()
934 }
935
936 pub(crate) fn persisted_row_slot_cache_lookup_out_of_bounds(
938 _model_path: &str,
939 _slot: usize,
940 ) -> Self {
941 Self::index_invariant()
942 }
943
944 pub(crate) fn persisted_row_primary_key_not_primary_key_encodable(
946 _data_key: impl fmt::Debug,
947 _detail: impl Sized,
948 ) -> Self {
949 Self::persisted_row_decode_corruption()
950 }
951
952 pub(crate) fn persisted_row_primary_key_slot_missing(_data_key: impl fmt::Debug) -> Self {
954 Self::persisted_row_decode_corruption()
955 }
956
957 pub(crate) fn persisted_row_key_mismatch() -> Self {
959 Self::store_corruption()
960 }
961
962 pub(crate) fn persisted_row_declared_field_missing(field_name: &str) -> Self {
964 Self::persisted_row_field_decode_corruption(field_name)
965 }
966
967 pub(crate) fn data_key_entity_mismatch() -> Self {
969 Self::store_corruption()
970 }
971
972 pub(crate) fn reverse_index_ordinal_overflow(
974 _source_path: &str,
975 _field_name: &str,
976 _target_path: &str,
977 _detail: impl Sized,
978 ) -> Self {
979 Self::index_internal()
980 }
981
982 pub(crate) fn reverse_index_entry_corrupted(
984 _source_path: &str,
985 _field_name: &str,
986 _target_path: &str,
987 _index_key: impl fmt::Debug,
988 _detail: impl Sized,
989 ) -> Self {
990 Self::index_corruption()
991 }
992
993 pub(crate) fn relation_target_store_missing(
995 _source_path: &str,
996 _field_name: &str,
997 _target_path: &str,
998 _store_path: &str,
999 _detail: impl Sized,
1000 ) -> Self {
1001 Self::executor_internal()
1002 }
1003
1004 pub(crate) fn relation_target_key_decode_failed(
1006 _context_label: &str,
1007 _source_path: &str,
1008 _field_name: &str,
1009 _target_path: &str,
1010 _detail: impl Sized,
1011 ) -> Self {
1012 Self::identity_corruption()
1013 }
1014
1015 pub(crate) fn relation_target_entity_mismatch(
1017 _context_label: &str,
1018 _source_path: &str,
1019 _field_name: &str,
1020 _target_path: &str,
1021 _target_entity_name: &str,
1022 _expected_tag: impl Sized,
1023 _actual_tag: impl Sized,
1024 ) -> Self {
1025 Self::store_corruption()
1026 }
1027
1028 pub(crate) fn relation_source_row_decode_failed(
1030 _source_path: &str,
1031 _field_name: &str,
1032 _target_path: &str,
1033 _detail: impl Sized,
1034 ) -> Self {
1035 Self::persisted_row_decode_corruption()
1036 }
1037
1038 pub(crate) fn relation_source_row_unsupported_scalar_relation_key(
1040 _source_path: &str,
1041 _field_name: &str,
1042 _target_path: &str,
1043 ) -> Self {
1044 Self::persisted_row_decode_corruption()
1045 }
1046
1047 pub(crate) fn relation_source_row_unsupported_key_kind(_field_kind: impl fmt::Debug) -> Self {
1049 Self::persisted_row_decode_corruption()
1050 }
1051
1052 pub(crate) fn reverse_index_relation_target_decode_invariant_violated(
1054 _source_path: &str,
1055 _field_name: &str,
1056 _target_path: &str,
1057 ) -> Self {
1058 Self::executor_internal()
1059 }
1060
1061 pub(crate) fn bytes_covering_component_payload_empty() -> Self {
1063 Self::index_corruption()
1064 }
1065
1066 pub(crate) fn bytes_covering_bool_payload_truncated() -> Self {
1068 Self::index_corruption()
1069 }
1070
1071 pub(crate) fn bytes_covering_component_payload_invalid_length() -> Self {
1073 Self::index_corruption()
1074 }
1075
1076 pub(crate) fn bytes_covering_bool_payload_invalid_value() -> Self {
1078 Self::index_corruption()
1079 }
1080
1081 pub(crate) fn bytes_covering_text_payload_invalid_terminator() -> Self {
1083 Self::index_corruption()
1084 }
1085
1086 pub(crate) fn bytes_covering_text_payload_trailing_bytes() -> Self {
1088 Self::index_corruption()
1089 }
1090
1091 pub(crate) fn bytes_covering_text_payload_invalid_utf8() -> Self {
1093 Self::index_corruption()
1094 }
1095
1096 pub(crate) fn bytes_covering_text_payload_invalid_escape_byte() -> Self {
1098 Self::index_corruption()
1099 }
1100
1101 pub(crate) fn bytes_covering_text_payload_missing_terminator() -> Self {
1103 Self::index_corruption()
1104 }
1105
1106 #[must_use]
1108 pub fn missing_persisted_slot(field_name: &'static str) -> Self {
1109 Self::persisted_row_field_decode_corruption(field_name)
1110 }
1111
1112 pub(crate) fn identity_corruption() -> Self {
1114 Self::new(ErrorClass::Corruption, ErrorOrigin::Identity)
1115 }
1116
1117 #[cold]
1119 #[inline(never)]
1120 pub(crate) fn store_unsupported() -> Self {
1121 Self::new(ErrorClass::Unsupported, ErrorOrigin::Store)
1122 }
1123
1124 pub(crate) fn schema_ddl_publication_race_lost(_entity_path: &'static str) -> Self {
1126 Self {
1127 class: ErrorClass::Unsupported,
1128 origin: ErrorOrigin::Store,
1129 detail: Some(ErrorDetail::Store(StoreError::SchemaDdlPublicationRaceLost)),
1130 }
1131 }
1132
1133 #[cfg(feature = "sql")]
1135 pub(crate) fn schema_ddl_set_not_null_validation_failed(
1136 _entity_path: &'static str,
1137 _column_name: &str,
1138 ) -> Self {
1139 Self {
1140 class: ErrorClass::Unsupported,
1141 origin: ErrorOrigin::Store,
1142 detail: Some(ErrorDetail::Store(
1143 StoreError::SchemaDdlSetNotNullValidationFailed,
1144 )),
1145 }
1146 }
1147
1148 pub(crate) fn unsupported_entity_tag_in_data_store(
1150 _entity_tag: crate::types::EntityTag,
1151 ) -> Self {
1152 Self::store_unsupported()
1153 }
1154
1155 #[cfg(not(test))]
1157 pub(crate) fn commit_memory_id_registration_failed(_err: impl Sized) -> Self {
1158 Self::store_internal()
1159 }
1160
1161 pub(crate) fn index_unsupported() -> Self {
1163 Self::new(ErrorClass::Unsupported, ErrorOrigin::Index)
1164 }
1165
1166 pub(crate) fn index_component_exceeds_max_size() -> Self {
1168 Self::index_unsupported()
1169 }
1170
1171 pub(crate) fn serialize_unsupported() -> Self {
1173 Self::new(ErrorClass::Unsupported, ErrorOrigin::Serialize)
1174 }
1175
1176 pub(crate) fn cursor_unsupported() -> Self {
1178 Self::new(ErrorClass::Unsupported, ErrorOrigin::Cursor)
1179 }
1180
1181 pub(crate) fn serialize_incompatible_persisted_format() -> Self {
1183 Self::new(
1184 ErrorClass::IncompatiblePersistedFormat,
1185 ErrorOrigin::Serialize,
1186 )
1187 }
1188
1189 #[cfg(feature = "sql")]
1192 pub(crate) fn query_unsupported_sql_feature(feature: diagnostic_code::SqlFeatureCode) -> Self {
1193 Self {
1194 class: ErrorClass::Unsupported,
1195 origin: ErrorOrigin::Query,
1196 detail: Some(ErrorDetail::Query(
1197 QueryErrorDetail::UnsupportedSqlFeature { feature },
1198 )),
1199 }
1200 }
1201
1202 #[cfg(feature = "sql")]
1205 pub(crate) fn query_sql_lowering(reason: diagnostic_code::SqlLoweringCode) -> Self {
1206 Self {
1207 class: ErrorClass::Unsupported,
1208 origin: ErrorOrigin::Query,
1209 detail: Some(ErrorDetail::Query(QueryErrorDetail::SqlLowering { reason })),
1210 }
1211 }
1212
1213 pub(crate) fn query_unsupported_projection(
1216 reason: diagnostic_code::QueryProjectionCode,
1217 ) -> Self {
1218 Self {
1219 class: ErrorClass::Unsupported,
1220 origin: ErrorOrigin::Query,
1221 detail: Some(ErrorDetail::Query(
1222 QueryErrorDetail::UnsupportedProjection { reason },
1223 )),
1224 }
1225 }
1226
1227 pub(crate) fn query_unknown_aggregate_target_field() -> Self {
1229 Self {
1230 class: ErrorClass::Unsupported,
1231 origin: ErrorOrigin::Query,
1232 detail: Some(ErrorDetail::Query(
1233 QueryErrorDetail::UnknownAggregateTargetField,
1234 )),
1235 }
1236 }
1237
1238 pub(crate) fn query_result_shape_mismatch(
1241 reason: diagnostic_code::QueryResultShapeCode,
1242 ) -> Self {
1243 Self {
1244 class: ErrorClass::Unsupported,
1245 origin: ErrorOrigin::Query,
1246 detail: Some(ErrorDetail::Query(QueryErrorDetail::ResultShapeMismatch {
1247 reason,
1248 })),
1249 }
1250 }
1251
1252 #[cfg(feature = "sql")]
1255 pub(crate) fn query_sql_surface_mismatch(
1256 mismatch: diagnostic_code::SqlSurfaceMismatchCode,
1257 ) -> Self {
1258 Self {
1259 class: ErrorClass::Unsupported,
1260 origin: ErrorOrigin::Query,
1261 detail: Some(ErrorDetail::Query(QueryErrorDetail::SqlSurfaceMismatch {
1262 mismatch,
1263 })),
1264 }
1265 }
1266
1267 #[cfg(feature = "sql")]
1269 pub(crate) fn query_sql_write_boundary(
1270 boundary: diagnostic_code::SqlWriteBoundaryCode,
1271 ) -> Self {
1272 Self {
1273 class: ErrorClass::Unsupported,
1274 origin: ErrorOrigin::Query,
1275 detail: Some(ErrorDetail::Query(QueryErrorDetail::SqlWriteBoundary {
1276 boundary,
1277 })),
1278 }
1279 }
1280
1281 pub fn store_not_found(_key: impl Sized) -> Self {
1282 Self {
1283 class: ErrorClass::NotFound,
1284 origin: ErrorOrigin::Store,
1285 detail: Some(ErrorDetail::Store(StoreError::NotFound)),
1286 }
1287 }
1288
1289 pub fn unsupported_entity_path(_path: impl Sized) -> Self {
1291 Self::store_unsupported()
1292 }
1293
1294 #[must_use]
1295 pub const fn is_not_found(&self) -> bool {
1296 matches!(self.detail, Some(ErrorDetail::Store(StoreError::NotFound)))
1297 }
1298
1299 #[cold]
1301 #[inline(never)]
1302 pub(crate) fn index_plan_corruption(origin: ErrorOrigin) -> Self {
1303 Self::new(ErrorClass::Corruption, origin)
1304 }
1305
1306 #[cold]
1308 #[inline(never)]
1309 pub(crate) fn index_plan_index_corruption() -> Self {
1310 Self::index_plan_corruption(ErrorOrigin::Index)
1311 }
1312
1313 #[cold]
1315 #[inline(never)]
1316 pub(crate) fn index_plan_store_corruption() -> Self {
1317 Self::index_plan_corruption(ErrorOrigin::Store)
1318 }
1319
1320 #[cold]
1322 #[inline(never)]
1323 pub(crate) fn index_plan_serialize_corruption() -> Self {
1324 Self::index_plan_corruption(ErrorOrigin::Serialize)
1325 }
1326
1327 #[cfg(test)]
1329 pub(crate) fn index_plan_invariant(origin: ErrorOrigin) -> Self {
1330 Self::new(ErrorClass::InvariantViolation, origin)
1331 }
1332
1333 #[cfg(test)]
1335 pub(crate) fn index_plan_store_invariant() -> Self {
1336 Self::index_plan_invariant(ErrorOrigin::Store)
1337 }
1338
1339 pub(crate) fn index_violation(_path: &str, _index_fields: &[&str]) -> Self {
1341 Self::new(ErrorClass::Conflict, ErrorOrigin::Index)
1342 }
1343}
1344
1345impl From<diagnostic_code::QueryReadAdmissionCode> for InternalError {
1346 fn from(reason: diagnostic_code::QueryReadAdmissionCode) -> Self {
1347 Self {
1348 class: ErrorClass::Unsupported,
1349 origin: ErrorOrigin::Query,
1350 detail: Some(ErrorDetail::Query(QueryErrorDetail::QueryReadAdmission {
1351 reason,
1352 })),
1353 }
1354 }
1355}
1356
1357impl fmt::Debug for InternalError {
1358 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1359 fmt_compact_diagnostic(
1360 f,
1361 self.diagnostic_code(),
1362 self.detail
1363 .as_ref()
1364 .and_then(ErrorDetail::diagnostic_detail),
1365 )
1366 }
1367}
1368
1369impl fmt::Display for InternalError {
1370 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1371 f.write_str(self.message())
1372 }
1373}
1374
1375impl std::error::Error for InternalError {}
1376
1377pub enum ErrorDetail {
1385 Store(StoreError),
1386 Query(QueryErrorDetail),
1387 }
1392
1393pub enum StoreError {
1401 NotFound,
1402
1403 Corrupt,
1404
1405 InvariantViolation,
1406
1407 SchemaDdlPublicationRaceLost,
1408
1409 SchemaDdlSetNotNullValidationFailed,
1410}
1411
1412pub enum QueryErrorDetail {
1419 NumericOverflow,
1420
1421 NumericNotRepresentable,
1422
1423 UnsupportedSqlFeature {
1424 feature: diagnostic_code::SqlFeatureCode,
1425 },
1426
1427 SqlLowering {
1428 reason: diagnostic_code::SqlLoweringCode,
1429 },
1430
1431 UnsupportedProjection {
1432 reason: diagnostic_code::QueryProjectionCode,
1433 },
1434
1435 UnknownAggregateTargetField,
1436
1437 ResultShapeMismatch {
1438 reason: diagnostic_code::QueryResultShapeCode,
1439 },
1440
1441 QueryReadAdmission {
1442 reason: diagnostic_code::QueryReadAdmissionCode,
1443 },
1444
1445 SqlSurfaceMismatch {
1446 mismatch: diagnostic_code::SqlSurfaceMismatchCode,
1447 },
1448
1449 SqlWriteBoundary {
1450 boundary: diagnostic_code::SqlWriteBoundaryCode,
1451 },
1452
1453 SchemaDdlAdmission {
1454 error: SchemaDdlAdmissionError,
1455 },
1456}
1457
1458impl fmt::Display for QueryErrorDetail {
1459 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1460 f.write_str(COMPACT_QUERY_DIAGNOSTIC_MESSAGE)
1461 }
1462}
1463
1464impl std::error::Error for QueryErrorDetail {}
1465
1466#[derive(Clone, Copy, Eq, PartialEq)]
1475pub enum SchemaDdlAdmissionError {
1476 MissingExpectedSchemaVersion,
1477
1478 MissingNextSchemaVersion,
1479
1480 StaleExpectedSchemaVersion,
1481
1482 InvalidExpectedSchemaVersion,
1483
1484 InvalidNextSchemaVersion,
1485
1486 AcceptedSchemaChangeWithoutVersionBump,
1487
1488 EmptyVersionBump,
1489
1490 VersionGap,
1491
1492 VersionRollback,
1493
1494 FingerprintMethodMismatch,
1495
1496 UnsupportedTransitionClass,
1497
1498 PhysicalRunnerMissing,
1499
1500 ValidationFailed,
1501
1502 PublicationRaceLost,
1503
1504 InvalidAddColumnDefault,
1505
1506 InvalidAlterColumnDefault,
1507
1508 GeneratedIndexDropRejected,
1509
1510 RequiredDropDefaultUnsupported,
1511
1512 GeneratedFieldDefaultChangeRejected,
1513
1514 GeneratedFieldNullabilityChangeRejected,
1515
1516 SetNotNullValidationFailed,
1517}
1518
1519impl fmt::Display for SchemaDdlAdmissionError {
1520 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1521 f.write_str(COMPACT_QUERY_DIAGNOSTIC_MESSAGE)
1522 }
1523}
1524
1525impl std::error::Error for SchemaDdlAdmissionError {}
1526
1527impl fmt::Debug for ErrorDetail {
1528 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1529 fmt_compact_diagnostic(f, self.diagnostic_code(), self.diagnostic_detail())
1530 }
1531}
1532
1533impl fmt::Debug for StoreError {
1534 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1535 fmt_compact_diagnostic(f, self.diagnostic_code(), self.diagnostic_detail())
1536 }
1537}
1538
1539impl fmt::Debug for QueryErrorDetail {
1540 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1541 fmt_compact_diagnostic(f, self.diagnostic_code(), self.diagnostic_detail())
1542 }
1543}
1544
1545impl fmt::Debug for SchemaDdlAdmissionError {
1546 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1547 fmt_compact_diagnostic(
1548 f,
1549 diagnostic_code::DiagnosticCode::SchemaDdlAdmission,
1550 Some(diagnostic_code::DiagnosticDetail::SchemaDdlAdmission {
1551 reason: self.diagnostic_code(),
1552 }),
1553 )
1554 }
1555}
1556
1557fn fmt_compact_diagnostic(
1558 f: &mut fmt::Formatter<'_>,
1559 code: diagnostic_code::DiagnosticCode,
1560 detail: Option<diagnostic_code::DiagnosticDetail>,
1561) -> fmt::Result {
1562 write!(
1563 f,
1564 "{}",
1565 diagnostic_code::ErrorCode::from_parts(code, detail).raw()
1566 )
1567}
1568
1569impl ErrorDetail {
1570 #[must_use]
1572 pub const fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
1573 match self {
1574 Self::Store(error) => error.diagnostic_code(),
1575 Self::Query(error) => error.diagnostic_code(),
1576 }
1577 }
1578
1579 #[must_use]
1581 pub const fn diagnostic_detail(&self) -> Option<diagnostic_code::DiagnosticDetail> {
1582 match self {
1583 Self::Store(error) => error.diagnostic_detail(),
1584 Self::Query(error) => error.diagnostic_detail(),
1585 }
1586 }
1587}
1588
1589impl StoreError {
1590 #[must_use]
1592 pub const fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
1593 match self {
1594 Self::NotFound => diagnostic_code::DiagnosticCode::StoreNotFound,
1595 Self::Corrupt => diagnostic_code::DiagnosticCode::StoreCorruption,
1596 Self::InvariantViolation => diagnostic_code::DiagnosticCode::StoreInvariantViolation,
1597 Self::SchemaDdlPublicationRaceLost | Self::SchemaDdlSetNotNullValidationFailed => {
1598 diagnostic_code::DiagnosticCode::SchemaDdlAdmission
1599 }
1600 }
1601 }
1602
1603 #[must_use]
1605 pub const fn diagnostic_detail(&self) -> Option<diagnostic_code::DiagnosticDetail> {
1606 match self {
1607 Self::SchemaDdlPublicationRaceLost => {
1608 Some(diagnostic_code::DiagnosticDetail::SchemaDdlAdmission {
1609 reason: diagnostic_code::SchemaDdlAdmissionCode::PublicationRaceLost,
1610 })
1611 }
1612 Self::SchemaDdlSetNotNullValidationFailed => {
1613 Some(diagnostic_code::DiagnosticDetail::SchemaDdlAdmission {
1614 reason: diagnostic_code::SchemaDdlAdmissionCode::SetNotNullValidationFailed,
1615 })
1616 }
1617 Self::NotFound | Self::Corrupt | Self::InvariantViolation => None,
1618 }
1619 }
1620}
1621
1622impl QueryErrorDetail {
1623 #[must_use]
1625 pub const fn diagnostic_code(&self) -> diagnostic_code::DiagnosticCode {
1626 match self {
1627 Self::NumericOverflow => diagnostic_code::DiagnosticCode::QueryNumericOverflow,
1628 Self::NumericNotRepresentable => {
1629 diagnostic_code::DiagnosticCode::QueryNumericNotRepresentable
1630 }
1631 Self::UnsupportedSqlFeature { .. } => {
1632 diagnostic_code::DiagnosticCode::QueryUnsupportedSqlFeature
1633 }
1634 Self::SqlLowering { .. } => diagnostic_code::DiagnosticCode::QueryUnsupportedSqlFeature,
1635 Self::UnsupportedProjection { .. } => {
1636 diagnostic_code::DiagnosticCode::QueryUnsupportedProjection
1637 }
1638 Self::UnknownAggregateTargetField => {
1639 diagnostic_code::DiagnosticCode::QueryUnknownAggregateTargetField
1640 }
1641 Self::ResultShapeMismatch { .. } => {
1642 diagnostic_code::DiagnosticCode::QueryResultShapeMismatch
1643 }
1644 Self::QueryReadAdmission { .. } => diagnostic_code::DiagnosticCode::QueryReadAdmission,
1645 Self::SqlSurfaceMismatch { .. } => {
1646 diagnostic_code::DiagnosticCode::QuerySqlSurfaceMismatch
1647 }
1648 Self::SqlWriteBoundary { .. } => diagnostic_code::DiagnosticCode::QuerySqlWriteBoundary,
1649 Self::SchemaDdlAdmission { .. } => diagnostic_code::DiagnosticCode::SchemaDdlAdmission,
1650 }
1651 }
1652
1653 #[must_use]
1655 pub const fn diagnostic_detail(&self) -> Option<diagnostic_code::DiagnosticDetail> {
1656 match self {
1657 Self::UnsupportedSqlFeature { feature } => {
1658 Some(diagnostic_code::DiagnosticDetail::UnsupportedSqlFeature { feature: *feature })
1659 }
1660 Self::SqlLowering { reason } => {
1661 Some(diagnostic_code::DiagnosticDetail::SqlLowering { reason: *reason })
1662 }
1663 Self::UnsupportedProjection { reason } => {
1664 Some(diagnostic_code::DiagnosticDetail::QueryProjection { reason: *reason })
1665 }
1666 Self::ResultShapeMismatch { reason } => {
1667 Some(diagnostic_code::DiagnosticDetail::QueryResultShape { reason: *reason })
1668 }
1669 Self::QueryReadAdmission { reason } => {
1670 Some(diagnostic_code::DiagnosticDetail::QueryReadAdmission { reason: *reason })
1671 }
1672 Self::SqlSurfaceMismatch { mismatch } => {
1673 Some(diagnostic_code::DiagnosticDetail::SqlSurfaceMismatch {
1674 mismatch: *mismatch,
1675 })
1676 }
1677 Self::SqlWriteBoundary { boundary } => {
1678 Some(diagnostic_code::DiagnosticDetail::SqlWriteBoundary {
1679 boundary: *boundary,
1680 })
1681 }
1682 Self::SchemaDdlAdmission { error } => {
1683 Some(diagnostic_code::DiagnosticDetail::SchemaDdlAdmission {
1684 reason: error.diagnostic_code(),
1685 })
1686 }
1687 Self::NumericOverflow
1688 | Self::NumericNotRepresentable
1689 | Self::UnknownAggregateTargetField => None,
1690 }
1691 }
1692}
1693
1694impl SchemaDdlAdmissionError {
1695 #[must_use]
1697 pub const fn diagnostic_code(&self) -> diagnostic_code::SchemaDdlAdmissionCode {
1698 match self {
1699 Self::MissingExpectedSchemaVersion => {
1700 diagnostic_code::SchemaDdlAdmissionCode::MissingExpectedSchemaVersion
1701 }
1702 Self::MissingNextSchemaVersion => {
1703 diagnostic_code::SchemaDdlAdmissionCode::MissingNextSchemaVersion
1704 }
1705 Self::StaleExpectedSchemaVersion => {
1706 diagnostic_code::SchemaDdlAdmissionCode::StaleExpectedSchemaVersion
1707 }
1708 Self::InvalidExpectedSchemaVersion => {
1709 diagnostic_code::SchemaDdlAdmissionCode::InvalidExpectedSchemaVersion
1710 }
1711 Self::InvalidNextSchemaVersion => {
1712 diagnostic_code::SchemaDdlAdmissionCode::InvalidNextSchemaVersion
1713 }
1714 Self::AcceptedSchemaChangeWithoutVersionBump => {
1715 diagnostic_code::SchemaDdlAdmissionCode::AcceptedSchemaChangeWithoutVersionBump
1716 }
1717 Self::EmptyVersionBump => diagnostic_code::SchemaDdlAdmissionCode::EmptyVersionBump,
1718 Self::VersionGap => diagnostic_code::SchemaDdlAdmissionCode::VersionGap,
1719 Self::VersionRollback => diagnostic_code::SchemaDdlAdmissionCode::VersionRollback,
1720 Self::FingerprintMethodMismatch => {
1721 diagnostic_code::SchemaDdlAdmissionCode::FingerprintMethodMismatch
1722 }
1723 Self::UnsupportedTransitionClass => {
1724 diagnostic_code::SchemaDdlAdmissionCode::UnsupportedTransitionClass
1725 }
1726 Self::PhysicalRunnerMissing => {
1727 diagnostic_code::SchemaDdlAdmissionCode::PhysicalRunnerMissing
1728 }
1729 Self::ValidationFailed => diagnostic_code::SchemaDdlAdmissionCode::ValidationFailed,
1730 Self::PublicationRaceLost => {
1731 diagnostic_code::SchemaDdlAdmissionCode::PublicationRaceLost
1732 }
1733 Self::InvalidAddColumnDefault => {
1734 diagnostic_code::SchemaDdlAdmissionCode::InvalidAddColumnDefault
1735 }
1736 Self::InvalidAlterColumnDefault => {
1737 diagnostic_code::SchemaDdlAdmissionCode::InvalidAlterColumnDefault
1738 }
1739 Self::GeneratedIndexDropRejected => {
1740 diagnostic_code::SchemaDdlAdmissionCode::GeneratedIndexDropRejected
1741 }
1742 Self::RequiredDropDefaultUnsupported => {
1743 diagnostic_code::SchemaDdlAdmissionCode::RequiredDropDefaultUnsupported
1744 }
1745 Self::GeneratedFieldDefaultChangeRejected => {
1746 diagnostic_code::SchemaDdlAdmissionCode::GeneratedFieldDefaultChangeRejected
1747 }
1748 Self::GeneratedFieldNullabilityChangeRejected => {
1749 diagnostic_code::SchemaDdlAdmissionCode::GeneratedFieldNullabilityChangeRejected
1750 }
1751 Self::SetNotNullValidationFailed => {
1752 diagnostic_code::SchemaDdlAdmissionCode::SetNotNullValidationFailed
1753 }
1754 }
1755 }
1756}
1757
1758#[repr(u16)]
1765#[derive(Clone, Copy, Eq, PartialEq)]
1766pub enum ErrorClass {
1767 Corruption,
1768 IncompatiblePersistedFormat,
1769 NotFound,
1770 Internal,
1771 Conflict,
1772 Unsupported,
1773 InvariantViolation,
1774}
1775
1776impl ErrorClass {
1777 #[must_use]
1779 pub const fn diagnostic_code(self, origin: ErrorOrigin) -> diagnostic_code::DiagnosticCode {
1780 match self {
1781 Self::Corruption if matches!(origin, ErrorOrigin::Store) => {
1782 diagnostic_code::DiagnosticCode::StoreCorruption
1783 }
1784 Self::Corruption => diagnostic_code::DiagnosticCode::RuntimeCorruption,
1785 Self::IncompatiblePersistedFormat => {
1786 diagnostic_code::DiagnosticCode::RuntimeIncompatiblePersistedFormat
1787 }
1788 Self::NotFound if matches!(origin, ErrorOrigin::Store) => {
1789 diagnostic_code::DiagnosticCode::StoreNotFound
1790 }
1791 Self::NotFound => diagnostic_code::DiagnosticCode::RuntimeNotFound,
1792 Self::Internal => diagnostic_code::DiagnosticCode::RuntimeInternal,
1793 Self::Conflict => diagnostic_code::DiagnosticCode::RuntimeConflict,
1794 Self::Unsupported => diagnostic_code::DiagnosticCode::RuntimeUnsupported,
1795 Self::InvariantViolation if matches!(origin, ErrorOrigin::Store) => {
1796 diagnostic_code::DiagnosticCode::StoreInvariantViolation
1797 }
1798 Self::InvariantViolation => diagnostic_code::DiagnosticCode::RuntimeInvariantViolation,
1799 }
1800 }
1801}
1802
1803impl fmt::Debug for ErrorClass {
1804 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1805 write!(f, "{}", *self as u16)
1806 }
1807}
1808
1809#[repr(u16)]
1816#[derive(Clone, Copy, Eq, PartialEq)]
1817pub enum ErrorOrigin {
1818 Serialize,
1819 Store,
1820 Index,
1821 Identity,
1822 Query,
1823 Planner,
1824 Cursor,
1825 Recovery,
1826 Response,
1827 Executor,
1828 Interface,
1829}
1830
1831impl ErrorOrigin {
1832 #[must_use]
1834 pub const fn diagnostic_origin(self) -> diagnostic_code::ErrorOrigin {
1835 match self {
1836 Self::Serialize => diagnostic_code::ErrorOrigin::Serialize,
1837 Self::Store => diagnostic_code::ErrorOrigin::Store,
1838 Self::Index => diagnostic_code::ErrorOrigin::Index,
1839 Self::Identity => diagnostic_code::ErrorOrigin::Identity,
1840 Self::Query => diagnostic_code::ErrorOrigin::Query,
1841 Self::Planner => diagnostic_code::ErrorOrigin::Planner,
1842 Self::Cursor => diagnostic_code::ErrorOrigin::Cursor,
1843 Self::Recovery => diagnostic_code::ErrorOrigin::Recovery,
1844 Self::Response => diagnostic_code::ErrorOrigin::Response,
1845 Self::Executor => diagnostic_code::ErrorOrigin::Executor,
1846 Self::Interface => diagnostic_code::ErrorOrigin::Interface,
1847 }
1848 }
1849}
1850
1851impl fmt::Debug for ErrorOrigin {
1852 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1853 write!(f, "{}", *self as u16)
1854 }
1855}