1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Errors reported while building a redaction policy.
use std::{
error::Error,
fmt,
};
use super::{
PolicyLocation,
Sensitivity,
};
/// Error returned when a redaction policy contains an invalid rule.
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PolicyError {
/// A supplied field name is empty after canonicalization.
EmptyFieldName {
/// Location where the invalid field was configured.
location: PolicyLocation,
},
/// A fixed mask has an empty replacement at the indicated level.
EmptyFixedReplacement {
/// Location where the fixed mask was configured.
location: PolicyLocation,
/// Sensitivity level containing the invalid fixed mask.
level: Sensitivity,
},
}
impl fmt::Display for PolicyError {
/// Formats a concise description of the invalid policy configuration.
///
/// # Parameters
///
/// * `formatter` - Destination formatting context.
///
/// # Returns
///
/// The formatter result from writing the error description.
///
/// # Errors
///
/// Returns [`fmt::Error`] when the destination rejects a write.
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyFieldName { location } => write!(
formatter,
"field name is empty after canonicalization in {location}",
),
Self::EmptyFixedReplacement { location, level } => write!(
formatter,
"fixed mask replacement for {level:?} sensitivity is empty in {location}",
),
}
}
}
impl Error for PolicyError {}