@@ -185,7 +185,12 @@ func (p *GoParser) ParseModule(mod *Module, dir string) (err error) {
185
185
return nil
186
186
}
187
187
}
188
- if err := p .parsePackage (p .pkgPathFromABS (path )); err != nil {
188
+ pkgPath , err := p .pkgPathFromABS (path )
189
+ if err == nil {
190
+ if err := p .parsePackage (pkgPath ); err != nil {
191
+ errs = append (errs , err )
192
+ }
193
+ } else {
189
194
errs = append (errs , err )
190
195
}
191
196
return nil
@@ -281,14 +286,24 @@ func (p *GoParser) searchName(name string) (ids []Identity, err error) {
281
286
if e != nil || info .IsDir () || shouldIgnoreFile (path ) || shouldIgnoreDir (filepath .Dir (path )) || ! strings .HasSuffix (path , ".go" ) {
282
287
return nil
283
288
}
284
- mod := p .pkgPathFromABS (path )
289
+ mod , e := p .pkgPathFromABS (path )
290
+ if e != nil {
291
+ fmt .Fprintf (os .Stderr , "get mod from pkgPathFromABS failed, err: %v" , e )
292
+ err = e
293
+ return nil
294
+ }
285
295
m := p .repo .Modules [mod ]
286
296
if m == nil {
287
297
dir , _ := filepath .Rel (p .homePageDir , path )
288
298
m = newModule (mod , dir )
289
299
p .repo .Modules [mod ] = m
290
300
}
291
- pkg := p .pkgPathFromABS (filepath .Dir (path ))
301
+ pkg , e := p .pkgPathFromABS (filepath .Dir (path ))
302
+ if e != nil {
303
+ fmt .Fprintf (os .Stderr , "get pkg from pkgPathFromABS failed, err: %v" , e )
304
+ err = e
305
+ return nil
306
+ }
292
307
// go AST parse file
293
308
fset := token .NewFileSet ()
294
309
fcontent := p .getFileBytes (path )
@@ -475,14 +490,15 @@ func (p *GoParser) getModuleFromPath(path string) (name string, dir string, rel
475
490
}
476
491
477
492
// FromABS converts an absolute path to local mod path
478
- func (p * GoParser ) pkgPathFromABS (path string ) PkgPath {
493
+ func (p * GoParser ) pkgPathFromABS (path string ) ( PkgPath , error ) {
479
494
mod , _ , rel := p .getModuleFromPath (path )
480
495
if mod == "" {
481
- panic ("not found package from " + path )
496
+ fmt .Fprintf (os .Stderr , "not found package from %s \n " , path )
497
+ return mod , fmt .Errorf ("not found package from %s " , path )
482
498
}
483
499
if rel != "" && rel != "." {
484
- return mod + "/" + rel
500
+ return mod + "/" + rel , nil
485
501
} else {
486
- return mod
502
+ return mod , nil
487
503
}
488
504
}
0 commit comments