Skip to content

Commit

Permalink
internal/debug: bug fix: do not panic when go-list fails
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Oct 18, 2024
1 parent d42916d commit 0ce1f22
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/debug/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package debug

import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
Expand All @@ -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)))
})
Expand Down

0 comments on commit 0ce1f22

Please sign in to comment.