diff --git a/rust/catalyst-types/src/problem_report.rs b/rust/catalyst-types/src/problem_report.rs index 5f2f027774f..6967316d0c4 100644 --- a/rust/catalyst-types/src/problem_report.rs +++ b/rust/catalyst-types/src/problem_report.rs @@ -48,6 +48,13 @@ enum Kind { /// Explanation of the failed or problematic validation explanation: String, }, + /// Duplicate field was detected. + DuplicateField { + /// The duplicated field. + field: String, + /// Additional information about the duplicate field. + description: String, + }, /// An uncategorized problem was encountered. Use only for rare problems, otherwise /// make a new problem kind. Other { @@ -337,6 +344,40 @@ impl ProblemReport { ); } + /// Reports that duplicate field was detected in the problem report. + /// + /// This method adds an entry to the problem report indicating that duplicate field + /// is found, along with the description of the duplicate field and any additional + /// context. + /// + /// # Arguments + /// + /// * `field`: A string slice representing the value of the duplicate field. + /// * `description`: An additional information about the duplicate field. + /// * `context`: A string slice providing additional context or information about + /// where and why this duplicate field was detected. + /// + /// # Example + /// + /// ```rust + /// # use catalyst_types::problem_report::ProblemReport; + /// let report = ProblemReport::new("RBAC Registration Decoding"); + /// report.duplicate_field( + /// "key 0", + /// "key is already defined, redundant key found in item 6 in RBAC map", + /// "RBAC purpose", + /// ); + /// ``` + pub fn duplicate_field(&self, field: &str, description: &str, context: &str) { + self.add_entry( + Kind::DuplicateField { + field: field.to_owned(), + description: description.to_owned(), + }, + context, + ); + } + /// Reports an uncategorized problem with the given description and context. /// /// This method is intended for use in rare situations where a specific type of