1- //! Output and accessibility configuration for screen-reader compatible CLI.
1+ . //! Output and accessibility configuration for screen-reader compatible CLI.
22//!
33//! Supports `NO_COLOR` (disable ANSI colors) and `--no-unicode` (ASCII-only output).
44
@@ -42,6 +42,8 @@ pub struct DiagnosticRecord {
4242 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
4343 pub detail : Option < String > ,
4444 pub severity : DiagnosticSeverity ,
45+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
46+ pub category : Option < String > ,
4547}
4648
4749impl DiagnosticRecord {
@@ -56,9 +58,15 @@ impl DiagnosticRecord {
5658 summary : summary. into ( ) ,
5759 detail,
5860 severity,
61+ category : None ,
5962 }
6063 }
6164
65+ pub fn with_category ( mut self , category : impl Into < String > ) -> Self {
66+ self . category = Some ( category. into ( ) ) ;
67+ self
68+ }
69+
6270 pub fn display_line ( & self ) -> String {
6371 match & self . detail {
6472 Some ( detail) if !detail. is_empty ( ) => format ! (
@@ -276,6 +284,17 @@ pub struct BatchExecutionResult {
276284 pub results : Vec < BatchResult > ,
277285}
278286
287+ pub fn categorize_error ( error : & str ) -> & ' static str {
288+ let lower_err = error. to_lowercase ( ) ;
289+ if lower_err. contains ( "time" ) && lower_err. contains ( "out" ) {
290+ "timeout"
291+ } else if lower_err. contains ( "parser failure" ) || lower_err. contains ( "invalid arguments" ) {
292+ "parser_failure"
293+ } else {
294+ "contract_failure"
295+ }
296+ }
297+
279298pub fn collect_runtime_diagnostics (
280299 source_map_loaded : bool ,
281300 budget : & crate :: inspector:: budget:: BudgetInfo ,
@@ -334,7 +353,7 @@ pub fn collect_runtime_diagnostics(
334353 "The most recent debugger action failed." ,
335354 Some ( error. to_string ( ) ) ,
336355 DiagnosticSeverity :: Error ,
337- ) ) ;
356+ ) . with_category ( categorize_error ( error ) ) ) ;
338357 }
339358
340359 diagnostics
@@ -683,4 +702,18 @@ mod tests {
683702 assert ! ( json. contains( "metadata" ) ) ;
684703 assert ! ( json. contains( "contract.wasm" ) ) ;
685704 }
705+
706+ #[ test]
707+ fn test_diagnostic_record_category ( ) {
708+ let record = DiagnosticRecord :: new ( "test" , "summary" , None , DiagnosticSeverity :: Error )
709+ . with_category ( "timeout" ) ;
710+ assert_eq ! ( record. category. as_deref( ) , Some ( "timeout" ) ) ;
711+ }
712+
713+ #[ test]
714+ fn test_categorize_error ( ) {
715+ assert_eq ! ( categorize_error( "Execution timed out after 30 seconds" ) , "timeout" ) ;
716+ assert_eq ! ( categorize_error( "Parser failure in function 'test'" ) , "parser_failure" ) ;
717+ assert_eq ! ( categorize_error( "Contract failure: trap" ) , "contract_failure" ) ;
718+ }
686719}
0 commit comments