Skip to content

Commit d50bfc2

Browse files
committed
feat(catalyst-types): add duplicate data error report
Signed-off-by: bkioshn <[email protected]>
1 parent 009063a commit d50bfc2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

rust/catalyst-types/src/problem_report.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ enum Kind {
4848
/// Explanation of the failed or problematic validation
4949
explanation: String,
5050
},
51+
/// Duplicate data was detected.
52+
DuplicateData {
53+
/// The detected duplicate value.
54+
value: String,
55+
},
5156
/// An uncategorized problem was encountered. Use only for rare problems, otherwise
5257
/// make a new problem kind.
5358
Other {
@@ -337,6 +342,33 @@ impl ProblemReport {
337342
);
338343
}
339344

345+
/// Reports that duplicate data was detected in the problem report.
346+
///
347+
/// This method adds an entry to the problem report indicating that duplicate data
348+
/// is found, along with the value of the duplicate data and any additional context.
349+
///
350+
/// # Arguments
351+
///
352+
/// * `value`: A string slice representing the value of the duplicate data.
353+
/// * `context`: A string slice providing additional context or information about
354+
/// where and why this duplicate data was detected.
355+
///
356+
/// # Example
357+
///
358+
/// ```rust
359+
/// use catalyst_types::problem_report::ProblemReport;
360+
/// let report = ProblemReport::new("RBAC Registration Decoding");
361+
/// report.duplicate_data("RBAC Purpose key at item 6 in map", "0");
362+
/// ```
363+
pub fn duplicate_data(&self, value: &str, context: &str) {
364+
self.add_entry(
365+
Kind::DuplicateData {
366+
value: value.to_owned(),
367+
},
368+
context,
369+
);
370+
}
371+
340372
/// Reports an uncategorized problem with the given description and context.
341373
///
342374
/// This method is intended for use in rare situations where a specific type of

0 commit comments

Comments
 (0)