@@ -274,7 +274,13 @@ impl<'a> Visitor<'a> {
274
274
) ;
275
275
}
276
276
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
+ ) {
278
284
let ( start_line, start_column, end_line, end_column) = location_for ( self , node) ;
279
285
let loc = location (
280
286
self . trap_writer ,
@@ -284,26 +290,38 @@ impl<'a> Visitor<'a> {
284
290
end_line,
285
291
end_column,
286
292
) ;
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) ;
295
304
}
296
305
297
306
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
+ ) ;
305
314
return false ;
306
315
}
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
+ } ;
307
325
308
326
let id = self . trap_writer . fresh_id ( ) ;
309
327
@@ -383,15 +401,13 @@ impl<'a> Visitor<'a> {
383
401
}
384
402
}
385
403
_ => {
386
- let error_message = format ! ( "unknown table type: '{}'" , node. kind( ) ) ;
387
404
self . record_parse_error (
388
405
loc,
389
406
self . diagnostics_writer
390
- . message ( "parse-error" , "Parse error" )
407
+ . new_entry ( "parse-error" , "Parse error" )
391
408
. severity ( diagnostics:: Severity :: Error )
392
409
. 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 ( ) ] ) ,
395
411
) ;
396
412
397
413
valid = false ;
@@ -439,23 +455,29 @@ impl<'a> Visitor<'a> {
439
455
values. push ( trap:: Arg :: Label ( child_node. label ) ) ;
440
456
}
441
457
} 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 ,
448
468
) ;
449
- self . record_parse_error_for_node ( error_message, * node) ;
450
469
}
451
470
} 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 ,
457
480
) ;
458
- self . record_parse_error_for_node ( error_message, * node) ;
459
481
}
460
482
}
461
483
let mut args = Vec :: new ( ) ;
@@ -471,14 +493,14 @@ impl<'a> Visitor<'a> {
471
493
let error_message = format ! (
472
494
"{} for field: {}::{}" ,
473
495
if child_values. is_empty( ) {
474
- "missing value"
496
+ "Missing value"
475
497
} else {
476
- "too many values"
498
+ "Too many values"
477
499
} ,
478
500
node. kind( ) ,
479
501
column_name
480
502
) ;
481
- self . record_parse_error_for_node ( error_message, * node) ;
503
+ self . record_parse_error_for_node ( & error_message, & [ ] , * node, false ) ;
482
504
}
483
505
}
484
506
Storage :: Table {
@@ -488,13 +510,12 @@ impl<'a> Visitor<'a> {
488
510
} => {
489
511
for ( index, child_value) in child_values. iter ( ) . enumerate ( ) {
490
512
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 ,
495
518
) ;
496
-
497
- self . record_parse_error_for_node ( error_message, * node) ;
498
519
break ;
499
520
}
500
521
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)
591
612
visitor. diagnostics_writer . write (
592
613
visitor
593
614
. 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" , & [ ] )
597
617
. severity ( diagnostics:: Severity :: Error ) ,
598
618
) ;
599
619
}
@@ -607,13 +627,11 @@ fn location_for(visitor: &mut Visitor, n: Node) -> (usize, usize, usize, usize)
607
627
visitor. diagnostics_writer . write (
608
628
visitor
609
629
. 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
+ )
617
635
. severity ( diagnostics:: Severity :: Error ) ,
618
636
) ;
619
637
}
0 commit comments