qubit_codec/value/value_codec_registry_error.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! Value-codec registry errors.
10
11use thiserror::Error;
12
13use crate::ValueCodecRegistrationSource;
14
15/// Failure while freezing a value-codec registry.
16///
17/// Freezing rejects duplicate stable IDs and reports the lexically first
18/// conflicting ID together with all of its declaration sites. Sources are
19/// sorted by their fields; repeated identical sources are retained because
20/// each registration is reported.
21///
22/// # Examples
23///
24/// ```
25/// use qubit_codec::ValueCodecRegistrationSource;
26/// use qubit_codec::ValueCodecRegistryError;
27///
28/// let error = ValueCodecRegistryError::DuplicateId {
29/// id: "example.u32",
30/// sources: vec![ValueCodecRegistrationSource::new(
31/// "qubit-codec",
32/// "my_crate::codecs",
33/// "src/codec.rs",
34/// 42,
35/// )],
36/// };
37/// assert!(error.to_string().starts_with("duplicate value codec ID example.u32"));
38/// ```
39#[derive(Clone, Debug, Error)]
40#[must_use]
41pub enum ValueCodecRegistryError {
42 /// Multiple registrations claim one stable ID.
43 #[error("duplicate value codec ID {id} from {sources:?}")]
44 DuplicateId {
45 /// Conflicting stable ID.
46 id: &'static str,
47 /// Registration sources in deterministic order.
48 sources: Vec<ValueCodecRegistrationSource>,
49 },
50}