From 8cdc44b6f8a3f04b9daa666d2297413e3aa87d8a Mon Sep 17 00:00:00 2001 From: "yinxuran.lucky" Date: Thu, 8 Jan 2026 10:10:54 +0800 Subject: [PATCH 1/2] feat: add log --- lang/golang/parser/ctx.go | 2 +- lang/golang/parser/pkg.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lang/golang/parser/ctx.go b/lang/golang/parser/ctx.go index 89bdb37..299cc0c 100644 --- a/lang/golang/parser/ctx.go +++ b/lang/golang/parser/ctx.go @@ -121,7 +121,7 @@ func (p *GoParser) getFileBytes(path string) []byte { } bs, err := os.ReadFile(path) if err != nil { - panic(err) + panic(fmt.Sprintf("read file %s failed: %v", path, err)) } p.files[path] = bs return bs diff --git a/lang/golang/parser/pkg.go b/lang/golang/parser/pkg.go index e044397..356ffb9 100644 --- a/lang/golang/parser/pkg.go +++ b/lang/golang/parser/pkg.go @@ -229,6 +229,14 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e filePath = pkg.CompiledGoFiles[idx] } else { filePath = fset.Position(file.Pos()).Filename + if filePath == "" { + fmt.Printf("filename is empty\n") + if idx < len(pkg.CompiledGoFiles) { + fmt.Printf("use CompiledGoFiles[%d]: %s\n", idx, pkg.CompiledGoFiles[idx]) + filePath = pkg.CompiledGoFiles[idx] + } + fmt.Printf("id: %v, CompiledGoFiles: %v, filePath: %s\n", idx, pkg.CompiledGoFiles, filePath) + } } var skip bool for _, exclude := range p.exclues { From 23aa12627732710d43b6f5ba716dcb2bfbb61f0c Mon Sep 17 00:00:00 2001 From: "yinxuran.lucky" Date: Thu, 8 Jan 2026 10:51:51 +0800 Subject: [PATCH 2/2] feat: skip nil file path --- lang/golang/parser/pkg.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lang/golang/parser/pkg.go b/lang/golang/parser/pkg.go index 356ffb9..7481650 100644 --- a/lang/golang/parser/pkg.go +++ b/lang/golang/parser/pkg.go @@ -230,12 +230,8 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e } else { filePath = fset.Position(file.Pos()).Filename if filePath == "" { - fmt.Printf("filename is empty\n") - if idx < len(pkg.CompiledGoFiles) { - fmt.Printf("use CompiledGoFiles[%d]: %s\n", idx, pkg.CompiledGoFiles[idx]) - filePath = pkg.CompiledGoFiles[idx] - } - fmt.Printf("id: %v, CompiledGoFiles: %v, filePath: %s\n", idx, pkg.CompiledGoFiles, filePath) + fmt.Fprintf(os.Stderr, "filename is empty, pkg: %s\n", pkg.ID) + continue } } var skip bool