Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module github.com/visualfc/gotools

go 1.25.0
go 1.26.0

require (
github.com/creack/pty v1.1.21
github.com/pmezard/go-difflib v1.0.0
github.com/visualfc/gomod v0.1.2
github.com/visualfc/goversion v1.1.0
golang.org/x/tools v0.49.0
golang.org/x/tools v0.52.0
)

require (
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/mod v0.39.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/mod v0.42.0 // indirect
golang.org/x/sync v0.24.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ github.com/visualfc/goversion v1.1.0 h1:EN0YQGRkeGoWTPxPNTnbhyNQyas5leKH5U5lL4t8
github.com/visualfc/goversion v1.1.0/go.mod h1:Gr3s6bW8NTomhheImwAttqno97Mw6pAnFn2dU8/EMa8=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/mod v0.39.0 h1:UF5zwQdCRRUpHfyPwr7d4UrGiVeldIsogtzWVnczL74=
golang.org/x/mod v0.39.0/go.mod h1:bvIbwjQ0HUFFf5AKukeeYQG4ZBUG9yxQbR9aEweIwYY=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
14 changes: 10 additions & 4 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -256,8 +257,11 @@ func runTypes(cmd *command.Command, args []string) error {
}
conf := NewPkgConfig(false, !typesSkipTests)
pkg, outconf, err := w.Check(pkgName, conf, cursor)
if err != nil {
return fmt.Errorf("error loading package %q: %w", pkgName, err)
}
if pkg == nil {
return fmt.Errorf("error import path %v", err)
return fmt.Errorf("error loading package %q: no package returned", pkgName)
}
if cursor != nil && w.findMode.IsValid() {
return w.LookupCursor(pkg, outconf, cursor)
Expand Down Expand Up @@ -501,9 +505,11 @@ func (w *PkgWalker) checkFiles(dir string, files []string) *FilesCheck {

func (w *PkgWalker) ImportHelper(parentDir string, name string, import_path string, conf *PkgConfig, cursor *FileCursor) (pkg *types.Package, outconf *PkgConfig, err error) {
defer func() {
err := recover()
if err != nil && typesVerbose {
fmt.Println(w.cmd.Stderr, err)
if recovered := recover(); recovered != nil {
err = fmt.Errorf("panic while loading package %q: %v", name, recovered)
if typesVerbose {
fmt.Fprintf(w.cmd.Stderr, "%v\n%s", err, debug.Stack())
}
}
}()

Expand Down
11 changes: 11 additions & 0 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"go/build"
"os"
"strings"
"testing"
)

Expand All @@ -21,6 +22,16 @@ func TestTypes(t *testing.T) {
w.LookupCursor(pkg, conf, cursor)
}

func TestImportHelperReturnsRecoveredPanics(t *testing.T) {
w := NewPkgWalker(nil)
w.SetOutput(os.Stdout, os.Stderr)

_, _, err := w.ImportHelper("", "example.com/panic", "", DefaultPkgConfig(), nil)
if err == nil || !strings.Contains(err.Error(), "panic while loading package") {
t.Fatalf("ImportHelper error = %v, want recovered panic error", err)
}
}

func test_error() {
e := fmt.Errorf("error_test")
_ = e.Error()
Expand Down
Loading