Skip to content

Commit

Permalink
fix: Convert loading panic -> error & delete index (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Oct 26, 2023
1 parent acd1632 commit 89c0adf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cmd/scip-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,20 @@ func mainErr() error {
}
}

removeOutFileIfPresent := func() {
if fileInfo, err := os.Stat(outFile); err == nil && fileInfo.Mode().IsRegular() {
os.RemoveAll(outFile)
}
}

defer func() {
if r := recover(); r != nil {
removeOutFileIfPresent()
}
}()

if err := index.Index(writer, options); err != nil {
removeOutFileIfPresent()
return err
}

Expand Down
14 changes: 12 additions & 2 deletions internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ func LoadPackages(

projectPackages = make(PackageLookup)

if err := output.WithProgress("Loading Packages", func() error {
var panicResult any
err = output.WithProgress("Loading Packages", func() error {
defer func() {
panicResult = recover()
}()

cfg := getConfig(moduleRoot, opts)
pkgs, err := packages.Load(cfg, "./...")
if err != nil {
Expand All @@ -90,7 +95,12 @@ func LoadPackages(
}

return nil
}); err != nil {
})
if err == nil && panicResult != nil {
err = fmt.Errorf("during package loading: %v", panicResult)
}

if err != nil {
return nil, nil, err
}

Expand Down

0 comments on commit 89c0adf

Please sign in to comment.