@@ -55,6 +55,14 @@ enum Kind {
5555 /// Additional information about the duplicate field.
5656 description : String ,
5757 } ,
58+ ConversionError {
59+ /// The field that failed to convert
60+ field : String ,
61+ /// The value that failed to convert
62+ value : String ,
63+ /// The type that the value was expected to convert to
64+ expected_type : String ,
65+ } ,
5866 /// An uncategorized problem was encountered. Use only for rare problems, otherwise
5967 /// make a new problem kind.
6068 Other {
@@ -78,7 +86,9 @@ struct Report(ConcurrentVec<Entry>);
7886
7987impl Serialize for Report {
8088 fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
81- where S : serde:: Serializer {
89+ where
90+ S : serde:: Serializer ,
91+ {
8292 let mut seq = serializer. serialize_seq ( Some ( self . 0 . len ( ) ) ) ?;
8393 for e in self . 0 . iter_cloned ( ) {
8494 seq. serialize_element ( & e) ?;
@@ -93,7 +103,9 @@ struct Context(Arc<String>);
93103
94104impl Serialize for Context {
95105 fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
96- where S : serde:: Serializer {
106+ where
107+ S : serde:: Serializer ,
108+ {
97109 let str = self . 0 . as_ref ( ) ;
98110 serializer. serialize_str ( str)
99111 }
@@ -378,6 +390,35 @@ impl ProblemReport {
378390 ) ;
379391 }
380392
393+ /// Reports a conversion error.
394+ ///
395+ /// This method adds an entry to the problem report indicating that a field failed to convert
396+ /// to the expected type, along with the value that failed to convert and the expected type.
397+ ///
398+ /// # Arguments
399+ ///
400+ /// * `field`: A string slice representing the field that failed to convert.
401+ /// * `value`: A string slice representing the value that failed to convert.
402+ /// * `expected_type`: A string slice representing the type that the value was expected to convert to.
403+ ///
404+ /// # Example
405+ ///
406+ /// ```rust
407+ /// use catalyst_types::problem_report::ProblemReport;
408+ /// let report = ProblemReport::new("RBAC Registration Decoding");
409+ /// report.conversion_error("address bytes", "[1, 2, 3, 4]", "Address", "RBAC stake address");
410+ /// ```
411+ pub fn conversion_error ( & self , field : & str , value : & str , expected_type : & str , context : & str ) {
412+ self . add_entry (
413+ Kind :: ConversionError {
414+ field : field. to_owned ( ) ,
415+ value : value. to_owned ( ) ,
416+ expected_type : expected_type. to_owned ( ) ,
417+ } ,
418+ context,
419+ ) ;
420+ }
421+
381422 /// Reports an uncategorized problem with the given description and context.
382423 ///
383424 /// This method is intended for use in rare situations where a specific type of
0 commit comments