From d50bfc25d58c277d72ca252a41e50d75e2d5647d Mon Sep 17 00:00:00 2001 From: bkioshn Date: Mon, 6 Jan 2025 12:17:30 +0700 Subject: [PATCH 1/4] feat(catalyst-types): add duplicate data error report Signed-off-by: bkioshn --- rust/catalyst-types/src/problem_report.rs | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/rust/catalyst-types/src/problem_report.rs b/rust/catalyst-types/src/problem_report.rs index 5f2f027774..e507026e7f 100644 --- a/rust/catalyst-types/src/problem_report.rs +++ b/rust/catalyst-types/src/problem_report.rs @@ -48,6 +48,11 @@ enum Kind { /// Explanation of the failed or problematic validation explanation: String, }, + /// Duplicate data was detected. + DuplicateData { + /// The detected duplicate value. + value: String, + }, /// An uncategorized problem was encountered. Use only for rare problems, otherwise /// make a new problem kind. Other { @@ -337,6 +342,33 @@ impl ProblemReport { ); } + /// Reports that duplicate data was detected in the problem report. + /// + /// This method adds an entry to the problem report indicating that duplicate data + /// is found, along with the value of the duplicate data and any additional context. + /// + /// # Arguments + /// + /// * `value`: A string slice representing the value of the duplicate data. + /// * `context`: A string slice providing additional context or information about + /// where and why this duplicate data was detected. + /// + /// # Example + /// + /// ```rust + /// use catalyst_types::problem_report::ProblemReport; + /// let report = ProblemReport::new("RBAC Registration Decoding"); + /// report.duplicate_data("RBAC Purpose key at item 6 in map", "0"); + /// ``` + pub fn duplicate_data(&self, value: &str, context: &str) { + self.add_entry( + Kind::DuplicateData { + value: value.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 From ba3b41e89a5c95d051d8f773eeb27db659c85a36 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Mon, 6 Jan 2025 12:21:26 +0700 Subject: [PATCH 2/4] fix(catalyst-types): format Signed-off-by: bkioshn --- rust/catalyst-types/src/problem_report.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/catalyst-types/src/problem_report.rs b/rust/catalyst-types/src/problem_report.rs index e507026e7f..7c796dbc8b 100644 --- a/rust/catalyst-types/src/problem_report.rs +++ b/rust/catalyst-types/src/problem_report.rs @@ -351,7 +351,7 @@ impl ProblemReport { /// /// * `value`: A string slice representing the value of the duplicate data. /// * `context`: A string slice providing additional context or information about - /// where and why this duplicate data was detected. + /// where and why this duplicate data was detected. /// /// # Example /// From 835e6e5bba976792075814ae348684665b248cd9 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Mon, 6 Jan 2025 13:26:36 +0700 Subject: [PATCH 3/4] fix(catalyst-types): add duplicate field description and change name Signed-off-by: bkioshn --- rust/catalyst-types/src/problem_report.rs | 35 ++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/rust/catalyst-types/src/problem_report.rs b/rust/catalyst-types/src/problem_report.rs index 7c796dbc8b..3308f5065e 100644 --- a/rust/catalyst-types/src/problem_report.rs +++ b/rust/catalyst-types/src/problem_report.rs @@ -48,10 +48,12 @@ enum Kind { /// Explanation of the failed or problematic validation explanation: String, }, - /// Duplicate data was detected. - DuplicateData { - /// The detected duplicate value. - value: 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. @@ -342,28 +344,35 @@ impl ProblemReport { ); } - /// Reports that duplicate data was detected in the problem report. + /// Reports that duplicate field was detected in the problem report. /// - /// This method adds an entry to the problem report indicating that duplicate data - /// is found, along with the value of the duplicate data and any additional context. + /// 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 /// - /// * `value`: A string slice representing the value of the duplicate data. + /// * `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 data was detected. + /// 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_data("RBAC Purpose key at item 6 in map", "0"); + /// report.duplicate_field( + /// "key 0", + /// "key is already defined, redundant key found in item 6 in RBAC map", + /// "RBAC purpose", + /// ); /// ``` - pub fn duplicate_data(&self, value: &str, context: &str) { + pub fn duplicate_field(&self, field: &str, description: &str, context: &str) { self.add_entry( - Kind::DuplicateData { - value: value.to_owned(), + Kind::DuplicateField { + field: field.to_owned(), + description: description.to_owned(), }, context, ); From 987383fcd7d801477ec96de891ff3cac49289e5d Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 6 Jan 2025 14:29:52 +0700 Subject: [PATCH 4/4] Update rust/catalyst-types/src/problem_report.rs --- rust/catalyst-types/src/problem_report.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/catalyst-types/src/problem_report.rs b/rust/catalyst-types/src/problem_report.rs index 3308f5065e..6967316d0c 100644 --- a/rust/catalyst-types/src/problem_report.rs +++ b/rust/catalyst-types/src/problem_report.rs @@ -360,7 +360,7 @@ impl ProblemReport { /// # Example /// /// ```rust - /// use catalyst_types::problem_report::ProblemReport; + /// # use catalyst_types::problem_report::ProblemReport; /// let report = ProblemReport::new("RBAC Registration Decoding"); /// report.duplicate_field( /// "key 0",