codec_jcs/error.rs
1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use thiserror::Error;
6
7/// Error returned when JSON canonicalization (JCS) fails.
8#[derive(Debug, Error, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum JcsError {
11 /// The supplied bytes were not one complete valid JSON text.
12 #[error("jcs: invalid JSON text")]
13 InvalidJson,
14
15 /// A JSON object declared the same member name more than once.
16 #[error("jcs: duplicate object member name")]
17 DuplicateProperty,
18
19 /// A number was NaN or infinite, which JCS does not permit.
20 #[error("jcs: non-finite number is not allowed")]
21 NonFiniteNumber,
22
23 /// An exactly represented integer was outside the interoperable range.
24 #[error("jcs: integer is outside the interoperable IEEE-754 range")]
25 IntegerOutsideInteroperableRange,
26
27 /// Serializing the value to canonical JSON failed.
28 #[error("jcs: JSON serialization error")]
29 SerializationError,
30
31 /// Nesting exceeded [`MAX_NESTING_DEPTH`](crate::MAX_NESTING_DEPTH).
32 /// A defense-in-depth bound in case a caller builds or deserializes a
33 /// `serde_json::Value` without the parser's own depth limit.
34 #[error("jcs: nesting depth limit exceeded")]
35 DepthExceeded,
36}