qubit_redact/policy/json_depth_budget_error.rs
1// =============================================================================
2// Copyright (c) 2025 - 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Validation errors for JSON recursion-depth budgets.
9
10use std::{
11 error::Error,
12 fmt::{
13 self,
14 Display,
15 Formatter,
16 },
17};
18
19/// Reports which JSON recursion-depth invariant was violated.
20#[non_exhaustive]
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum JsonDepthBudgetError {
23 /// The recursive container depth limit was zero.
24 ZeroDepth,
25}
26
27impl Display for JsonDepthBudgetError {
28 /// Writes a concise description of the violated budget invariant.
29 ///
30 /// # Parameters
31 ///
32 /// * `formatter` - Destination formatting context.
33 ///
34 /// # Returns
35 ///
36 /// The formatter result after writing the error description.
37 ///
38 /// # Errors
39 ///
40 /// Returns [`fmt::Error`] when the destination rejects output.
41 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
42 match self {
43 Self::ZeroDepth => formatter
44 .write_str("JSON depth budget must be greater than zero"),
45 }
46 }
47}
48
49impl Error for JsonDepthBudgetError {}