@@ -449,60 +449,68 @@ var (
449
449
// extractError extracts the message and location of a frontend error
450
450
func (extraction * Extraction ) extractError (tw * trap.Writer , err packages.Error , pkglbl trap.Label , idx int ) {
451
451
var (
452
- lbl = tw .Labeler .FreshID ()
453
- tag = dbscheme .ErrorTags [err .Kind ]
454
- kind = dbscheme .ErrorTypes [err .Kind ].Index ()
455
- pos = err .Pos
456
- file = ""
457
- line = 0
458
- col = 0
459
- e error
452
+ lbl = tw .Labeler .FreshID ()
453
+ tag = dbscheme .ErrorTags [err .Kind ]
454
+ kind = dbscheme .ErrorTypes [err .Kind ].Index ()
455
+ pos = err .Pos
456
+ file = ""
457
+ line , col int
458
+ e error
460
459
)
461
460
462
- if parts := threePartPos . FindStringSubmatch ( pos ); parts != nil {
463
- // " file:line:col"
464
- col , e = strconv . Atoi ( parts [ 3 ] )
461
+ if pos == "" {
462
+ // extract a dummy file
463
+ file , e = filepath . Abs ( filepath . Join ( "." , "-" ) )
465
464
if e != nil {
466
- log .Printf ("Warning: malformed column number `%s`: %v" , parts [3 ], e )
465
+ file = filepath .Join ("." , "-" )
466
+ log .Printf ("Warning: failed to get absolute path for for %s" , file )
467
467
}
468
- line , e = strconv .Atoi (parts [2 ])
468
+ } else {
469
+ var rawfile string
470
+ if parts := threePartPos .FindStringSubmatch (pos ); parts != nil {
471
+ // "file:line:col"
472
+ col , e = strconv .Atoi (parts [3 ])
473
+ if e != nil {
474
+ log .Printf ("Warning: malformed column number `%s`: %v" , parts [3 ], e )
475
+ }
476
+ line , e = strconv .Atoi (parts [2 ])
477
+ if e != nil {
478
+ log .Printf ("Warning: malformed line number `%s`: %v" , parts [2 ], e )
479
+ }
480
+ rawfile = parts [1 ]
481
+ } else if parts := twoPartPos .FindStringSubmatch (pos ); parts != nil {
482
+ // "file:line"
483
+ line , e = strconv .Atoi (parts [2 ])
484
+ if e != nil {
485
+ log .Printf ("Warning: malformed line number `%s`: %v" , parts [2 ], e )
486
+ }
487
+ rawfile = parts [1 ]
488
+ } else if pos != "" && pos != "-" {
489
+ log .Printf ("Warning: malformed error position `%s`" , pos )
490
+ }
491
+ afile , e := filepath .Abs (rawfile )
469
492
if e != nil {
470
- log .Printf ("Warning: malformed line number `%s`: %v" , parts [2 ], e )
493
+ log .Printf ("Warning: failed to get absolute path for for %s" , file )
494
+ afile = file
471
495
}
472
- file = parts [1 ]
473
- } else if parts := twoPartPos .FindStringSubmatch (pos ); parts != nil {
474
- // "file:line"
475
- line , e = strconv .Atoi (parts [2 ])
496
+ file , e = filepath .EvalSymlinks (afile )
476
497
if e != nil {
477
- log .Printf ("Warning: malformed line number `%s`: %v" , parts [2 ], e )
498
+ log .Printf ("Warning: failed to evaluate symlinks for %s" , afile )
499
+ file = afile
478
500
}
479
- file = parts [1 ]
480
- } else if pos != "" && pos != "-" {
481
- log .Printf ("Warning: malformed error position `%s`" , pos )
482
- }
483
- afile , e := filepath .Abs (file )
484
- if e != nil {
485
- log .Printf ("Warning: failed to get absolute path for for %s" , file )
486
- afile = file
487
- }
488
- ffile , e := filepath .EvalSymlinks (afile )
489
- if e != nil {
490
- log .Printf ("Warning: failed to evaluate symlinks for %s" , afile )
491
- ffile = afile
492
- }
493
- transformed := filepath .ToSlash (srcarchive .TransformPath (ffile ))
494
501
495
- extraction .extractFileInfo (tw , ffile )
502
+ extraction .extractFileInfo (tw , file )
503
+ }
496
504
497
505
extraction .Lock .Lock ()
498
-
506
+ flbl := extraction . StatWriter . Labeler . FileLabelFor ( file )
499
507
diagLbl := extraction .StatWriter .Labeler .FreshID ()
500
- flbl := extraction .StatWriter .Labeler .FileLabelFor (ffile )
501
508
dbscheme .DiagnosticsTable .Emit (
502
509
extraction .StatWriter , diagLbl , 1 , tag , err .Msg , err .Msg ,
503
510
emitLocation (extraction .StatWriter , flbl , line , col , line , col ))
504
511
dbscheme .DiagnosticForTable .Emit (extraction .StatWriter , diagLbl , extraction .Label , extraction .GetFileIdx (file ), extraction .GetNextErr (file ))
505
512
extraction .Lock .Unlock ()
513
+ transformed := filepath .ToSlash (srcarchive .TransformPath (file ))
506
514
dbscheme .ErrorsTable .Emit (tw , lbl , kind , err .Msg , pos , transformed , line , col , pkglbl , idx )
507
515
}
508
516
0 commit comments