From 0ce1f2292e6a7bd3605f5820b85fdaac5e083b18 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 18 Oct 2024 15:28:42 +0900 Subject: [PATCH] internal/debug: bug fix: do not panic when go-list fails --- internal/debug/caller.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/debug/caller.go b/internal/debug/caller.go index 3fd059235..edc9b6441 100644 --- a/internal/debug/caller.go +++ b/internal/debug/caller.go @@ -15,8 +15,10 @@ package debug import ( + "bytes" "errors" "fmt" + "os" "os/exec" "path" "path/filepath" @@ -41,13 +43,17 @@ const ( // FirstCaller returns the file and line number of the first caller outside of Ebitengine. func FirstCaller() (file string, line int, callerType CallerType) { ebitengineFileDirOnce.Do(func() { + var stderr bytes.Buffer cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2") + cmd.Stderr = &stderr out, err := cmd.Output() if errors.Is(err, exec.ErrNotFound) { return } if err != nil { - panic(fmt.Sprintf("debug: go list -f {{.Dir}} failed: %v", err)) + fmt.Fprintf(os.Stderr, "debug: go list -f {{.Dir}} failed: %v\n", err) + fmt.Fprintf(os.Stderr, "%s\n", stderr.String()) + return } ebitengineFileDir = filepath.ToSlash(strings.TrimSpace(string(out))) })