Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 1666407

Browse files
author
Sauyon Lee
committed
Extract dummy files for errors with no location
1 parent 8dce08b commit 1666407

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

extractor/extractor.go

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -449,60 +449,68 @@ var (
449449
// extractError extracts the message and location of a frontend error
450450
func (extraction *Extraction) extractError(tw *trap.Writer, err packages.Error, pkglbl trap.Label, idx int) {
451451
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
460459
)
461460

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(".", "-"))
465464
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)
467467
}
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)
469492
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
471495
}
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)
476497
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
478500
}
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))
494501

495-
extraction.extractFileInfo(tw, ffile)
502+
extraction.extractFileInfo(tw, file)
503+
}
496504

497505
extraction.Lock.Lock()
498-
506+
flbl := extraction.StatWriter.Labeler.FileLabelFor(file)
499507
diagLbl := extraction.StatWriter.Labeler.FreshID()
500-
flbl := extraction.StatWriter.Labeler.FileLabelFor(ffile)
501508
dbscheme.DiagnosticsTable.Emit(
502509
extraction.StatWriter, diagLbl, 1, tag, err.Msg, err.Msg,
503510
emitLocation(extraction.StatWriter, flbl, line, col, line, col))
504511
dbscheme.DiagnosticForTable.Emit(extraction.StatWriter, diagLbl, extraction.Label, extraction.GetFileIdx(file), extraction.GetNextErr(file))
505512
extraction.Lock.Unlock()
513+
transformed := filepath.ToSlash(srcarchive.TransformPath(file))
506514
dbscheme.ErrorsTable.Emit(tw, lbl, kind, err.Msg, pos, transformed, line, col, pkglbl, idx)
507515
}
508516

0 commit comments

Comments
 (0)