@@ -274,7 +274,13 @@ impl<'a> Visitor<'a> {
274274 ) ;
275275 }
276276
277- fn record_parse_error_for_node ( & mut self , error_message : String , node : Node ) {
277+ fn record_parse_error_for_node (
278+ & mut self ,
279+ message : & str ,
280+ args : & [ & str ] ,
281+ node : Node ,
282+ status_page : bool ,
283+ ) {
278284 let ( start_line, start_column, end_line, end_column) = location_for ( self , node) ;
279285 let loc = location (
280286 self . trap_writer ,
@@ -284,26 +290,38 @@ impl<'a> Visitor<'a> {
284290 end_line,
285291 end_column,
286292 ) ;
287- self . record_parse_error (
288- loc,
289- self . diagnostics_writer
290- . message ( "parse-error" , "Parse error" )
291- . severity ( diagnostics:: Severity :: Error )
292- . location ( self . path , start_line, start_column, end_line, end_column)
293- . text ( & error_message) ,
294- ) ;
293+ let mut mesg = self
294+ . diagnostics_writer
295+ . new_entry ( "parse-error" , "Parse error" ) ;
296+ & mesg
297+ . severity ( diagnostics:: Severity :: Error )
298+ . location ( self . path , start_line, start_column, end_line, end_column)
299+ . message ( message, args) ;
300+ if status_page {
301+ & mesg. status_page ( ) ;
302+ }
303+ self . record_parse_error ( loc, & mesg) ;
295304 }
296305
297306 fn enter_node ( & mut self , node : Node ) -> bool {
298- if node. is_error ( ) || node . is_missing ( ) {
299- let error_message = if node . is_missing ( ) {
300- format ! ( " parse error: expecting '{}'" , node . kind ( ) )
301- } else {
302- "parse error" . to_string ( )
303- } ;
304- self . record_parse_error_for_node ( error_message , node ) ;
307+ if node. is_missing ( ) {
308+ self . record_parse_error_for_node (
309+ "A parse error occurred (expected {} symbol). Check the syntax of the file using the {} command. If the file is invalid, correct the error or exclude the file from analysis." ,
310+ & [ node . kind ( ) , "ruby -c" ] ,
311+ node ,
312+ true ,
313+ ) ;
305314 return false ;
306315 }
316+ if node. is_error ( ) {
317+ self . record_parse_error_for_node (
318+ "A parse error occurred. Check the syntax of the file using the {} command. If the file is invalid, correct the error or exclude the file from analysis." ,
319+ & [ "ruby -c" ] ,
320+ node,
321+ true ,
322+ ) ;
323+ return false ;
324+ } ;
307325
308326 let id = self . trap_writer . fresh_id ( ) ;
309327
@@ -383,15 +401,13 @@ impl<'a> Visitor<'a> {
383401 }
384402 }
385403 _ => {
386- let error_message = format ! ( "unknown table type: '{}'" , node. kind( ) ) ;
387404 self . record_parse_error (
388405 loc,
389406 self . diagnostics_writer
390- . message ( "parse-error" , "Parse error" )
407+ . new_entry ( "parse-error" , "Parse error" )
391408 . severity ( diagnostics:: Severity :: Error )
392409 . location ( self . path , start_line, start_column, end_line, end_column)
393- . text ( & error_message)
394- . status_page ( ) ,
410+ . message ( "Unknown table type: {}" , & [ node. kind ( ) ] ) ,
395411 ) ;
396412
397413 valid = false ;
@@ -439,23 +455,29 @@ impl<'a> Visitor<'a> {
439455 values. push ( trap:: Arg :: Label ( child_node. label ) ) ;
440456 }
441457 } else if field. name . is_some ( ) {
442- let error_message = format ! (
443- "type mismatch for field {}::{} with type {:?} != {:?}" ,
444- node. kind( ) ,
445- child_node. field_name. unwrap_or( "child" ) ,
446- child_node. type_name,
447- field. type_info
458+ self . record_parse_error_for_node (
459+ "Type mismatch for field {}::{} with type {} != {}" ,
460+ & [
461+ node. kind ( ) ,
462+ child_node. field_name . unwrap_or ( "child" ) ,
463+ & format ! ( "{:?}" , child_node. type_name) ,
464+ & format ! ( "{:?}" , field. type_info) ,
465+ ] ,
466+ * node,
467+ false ,
448468 ) ;
449- self . record_parse_error_for_node ( error_message, * node) ;
450469 }
451470 } else if child_node. field_name . is_some ( ) || child_node. type_name . named {
452- let error_message = format ! (
453- "value for unknown field: {}::{} and type {:?}" ,
454- node. kind( ) ,
455- & child_node. field_name. unwrap_or( "child" ) ,
456- & child_node. type_name
471+ self . record_parse_error_for_node (
472+ "Value for unknown field: {}::{} and type {}" ,
473+ & [
474+ node. kind ( ) ,
475+ & child_node. field_name . unwrap_or ( "child" ) ,
476+ & format ! ( "{:?}" , child_node. type_name) ,
477+ ] ,
478+ * node,
479+ false ,
457480 ) ;
458- self . record_parse_error_for_node ( error_message, * node) ;
459481 }
460482 }
461483 let mut args = Vec :: new ( ) ;
@@ -471,14 +493,14 @@ impl<'a> Visitor<'a> {
471493 let error_message = format ! (
472494 "{} for field: {}::{}" ,
473495 if child_values. is_empty( ) {
474- "missing value"
496+ "Missing value"
475497 } else {
476- "too many values"
498+ "Too many values"
477499 } ,
478500 node. kind( ) ,
479501 column_name
480502 ) ;
481- self . record_parse_error_for_node ( error_message, * node) ;
503+ self . record_parse_error_for_node ( & error_message, & [ ] , * node, false ) ;
482504 }
483505 }
484506 Storage :: Table {
@@ -488,13 +510,12 @@ impl<'a> Visitor<'a> {
488510 } => {
489511 for ( index, child_value) in child_values. iter ( ) . enumerate ( ) {
490512 if !* has_index && index > 0 {
491- let error_message = format ! (
492- "too many values for field: {}::{}" ,
493- node. kind( ) ,
494- table_name,
513+ self . record_parse_error_for_node (
514+ "Too many values for field: {}::{}" ,
515+ & [ node. kind ( ) , table_name] ,
516+ * node,
517+ false ,
495518 ) ;
496-
497- self . record_parse_error_for_node ( error_message, * node) ;
498519 break ;
499520 }
500521 let mut args = vec ! [ trap:: Arg :: Label ( parent_id) ] ;
@@ -591,9 +612,8 @@ fn location_for(visitor: &mut Visitor, n: Node) -> (usize, usize, usize, usize)
591612 visitor. diagnostics_writer . write (
592613 visitor
593614 . diagnostics_writer
594- . message ( "internal-error" , "Internal error" )
595- . text ( "expecting a line break symbol, but none found while correcting end column value" )
596- . status_page ( )
615+ . new_entry ( "internal-error" , "Internal error" )
616+ . message ( "Expecting a line break symbol, but none found while correcting end column value" , & [ ] )
597617 . severity ( diagnostics:: Severity :: Error ) ,
598618 ) ;
599619 }
@@ -607,13 +627,11 @@ fn location_for(visitor: &mut Visitor, n: Node) -> (usize, usize, usize, usize)
607627 visitor. diagnostics_writer . write (
608628 visitor
609629 . diagnostics_writer
610- . message ( "internal-error" , "Internal error" )
611- . text ( & format ! (
612- "cannot correct end column value: end_byte index {} is not in range [1,{}]" ,
613- index,
614- source. len( )
615- ) )
616- . status_page ( )
630+ . new_entry ( "internal-error" , "Internal error" )
631+ . message (
632+ "Cannot correct end column value: end_byte index {} is not in range [1,{}]" ,
633+ & [ & index. to_string ( ) , & source. len ( ) . to_string ( ) ] ,
634+ )
617635 . severity ( diagnostics:: Severity :: Error ) ,
618636 ) ;
619637 }
0 commit comments