mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 23:17:27 +01:00
internal/debug: bug fix: do not panic when go-list fails
This commit is contained in:
parent
d42916da44
commit
0ce1f2292e
@ -15,8 +15,10 @@
|
|||||||
package debug
|
package debug
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -41,13 +43,17 @@ const (
|
|||||||
// FirstCaller returns the file and line number of the first caller outside of Ebitengine.
|
// FirstCaller returns the file and line number of the first caller outside of Ebitengine.
|
||||||
func FirstCaller() (file string, line int, callerType CallerType) {
|
func FirstCaller() (file string, line int, callerType CallerType) {
|
||||||
ebitengineFileDirOnce.Do(func() {
|
ebitengineFileDirOnce.Do(func() {
|
||||||
|
var stderr bytes.Buffer
|
||||||
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2")
|
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", "github.com/hajimehoshi/ebiten/v2")
|
||||||
|
cmd.Stderr = &stderr
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if errors.Is(err, exec.ErrNotFound) {
|
if errors.Is(err, exec.ErrNotFound) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
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)))
|
ebitengineFileDir = filepath.ToSlash(strings.TrimSpace(string(out)))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user