Skip to content

Commit bfa2fc3

Browse files
bkioshnstevenj
andauthored
feat(rust/catalyst-types): Add duplicate data error report (#141)
* feat(catalyst-types): add duplicate data error report Signed-off-by: bkioshn <[email protected]> * fix(catalyst-types): format Signed-off-by: bkioshn <[email protected]> * fix(catalyst-types): add duplicate field description and change name Signed-off-by: bkioshn <[email protected]> * Update rust/catalyst-types/src/problem_report.rs --------- Signed-off-by: bkioshn <[email protected]> Co-authored-by: Steven Johnson <[email protected]>
1 parent 01f7d6c commit bfa2fc3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

rust/catalyst-types/src/problem_report.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ enum Kind {
4848
/// Explanation of the failed or problematic validation
4949
explanation: String,
5050
},
51+
/// Duplicate field was detected.
52+
DuplicateField {
53+
/// The duplicated field.
54+
field: String,
55+
/// Additional information about the duplicate field.
56+
description: String,
57+
},
5158
/// An uncategorized problem was encountered. Use only for rare problems, otherwise
5259
/// make a new problem kind.
5360
Other {
@@ -337,6 +344,40 @@ impl ProblemReport {
337344
);
338345
}
339346

347+
/// Reports that duplicate field was detected in the problem report.
348+
///
349+
/// This method adds an entry to the problem report indicating that duplicate field
350+
/// is found, along with the description of the duplicate field and any additional
351+
/// context.
352+
///
353+
/// # Arguments
354+
///
355+
/// * `field`: A string slice representing the value of the duplicate field.
356+
/// * `description`: An additional information about the duplicate field.
357+
/// * `context`: A string slice providing additional context or information about
358+
/// where and why this duplicate field was detected.
359+
///
360+
/// # Example
361+
///
362+
/// ```rust
363+
/// # use catalyst_types::problem_report::ProblemReport;
364+
/// let report = ProblemReport::new("RBAC Registration Decoding");
365+
/// report.duplicate_field(
366+
/// "key 0",
367+
/// "key is already defined, redundant key found in item 6 in RBAC map",
368+
/// "RBAC purpose",
369+
/// );
370+
/// ```
371+
pub fn duplicate_field(&self, field: &str, description: &str, context: &str) {
372+
self.add_entry(
373+
Kind::DuplicateField {
374+
field: field.to_owned(),
375+
description: description.to_owned(),
376+
},
377+
context,
378+
);
379+
}
380+
340381
/// Reports an uncategorized problem with the given description and context.
341382
///
342383
/// This method is intended for use in rare situations where a specific type of

0 commit comments

Comments
 (0)