Skip to content

Commit 0cc5873

Browse files
authored
feat: skip nil filepath when loadPackages (#145)
* feat: add log * feat: skip nil file path
1 parent ce097ba commit 0cc5873

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lang/golang/parser/ctx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (p *GoParser) getFileBytes(path string) []byte {
121121
}
122122
bs, err := os.ReadFile(path)
123123
if err != nil {
124-
panic(err)
124+
panic(fmt.Sprintf("read file %s failed: %v", path, err))
125125
}
126126
p.files[path] = bs
127127
return bs

lang/golang/parser/pkg.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e
229229
filePath = pkg.CompiledGoFiles[idx]
230230
} else {
231231
filePath = fset.Position(file.Pos()).Filename
232+
if filePath == "" {
233+
fmt.Fprintf(os.Stderr, "filename is empty, pkg: %s\n", pkg.ID)
234+
continue
235+
}
232236
}
233237
var skip bool
234238
for _, exclude := range p.exclues {

0 commit comments

Comments
 (0)