From ca8c36499d92b3963e0a8d4a7b837e757cd246c6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 24 Jul 2022 23:15:47 +0900 Subject: [PATCH] ebiten: recommend errors.Is instead of comparing the returned value directly Closes #2152 --- examples/fullscreen/main.go | 2 +- examples/keyboard/keyboard/gen.go | 2 +- examples/spriteshd/main.go | 2 +- examples/windowclosing/main.go | 2 +- internal/buffered/image_test.go | 2 +- internal/processtest/testdata/issue1753.go | 2 +- internal/processtest/testdata/issue2079.go | 2 +- internal/processtest/testdata/issue2089.go | 2 +- internal/processtest/testdata/issue2129.go | 2 +- internal/processtest/testdata/issue2154_1.go | 2 +- internal/processtest/testdata/issue2154_2.go | 2 +- internal/processtest/testdata/issue2162.go | 2 +- internal/processtest/testdata/issue2182.go | 2 +- internal/testing/testing.go | 2 +- run.go | 6 ++++-- 15 files changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index f703d945b..9275648a8 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -127,7 +127,7 @@ func main() { ebiten.SetFullscreen(true) ebiten.SetWindowTitle("Fullscreen (Ebiten Demo)") - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { log.Fatal(err) } } diff --git a/examples/keyboard/keyboard/gen.go b/examples/keyboard/keyboard/gen.go index 07ff3fe8d..34ab006ae 100644 --- a/examples/keyboard/keyboard/gen.go +++ b/examples/keyboard/keyboard/gen.go @@ -340,7 +340,7 @@ func (g *game) Layout(outw, outh int) (int, int) { func main() { g := &game{} - if err := ebiten.RunGame(g); err != regularTermination { + if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) { log.Fatal(err) } if err := outputKeyRectsGo(g.rects); err != nil { diff --git a/examples/spriteshd/main.go b/examples/spriteshd/main.go index f95866b23..0e2718e9e 100644 --- a/examples/spriteshd/main.go +++ b/examples/spriteshd/main.go @@ -202,7 +202,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func main() { ebiten.SetFullscreen(true) ebiten.SetWindowTitle("Sprites HD (Ebiten Demo)") - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { log.Fatal(err) } } diff --git a/examples/windowclosing/main.go b/examples/windowclosing/main.go index b51d54c38..84d701623 100644 --- a/examples/windowclosing/main.go +++ b/examples/windowclosing/main.go @@ -62,7 +62,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func main() { ebiten.SetWindowClosingHandled(true) ebiten.SetWindowTitle("Window Closing (Ebiten Demo)") - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { log.Fatal(err) } } diff --git a/internal/buffered/image_test.go b/internal/buffered/image_test.go index f2c9d66ca..3f2189519 100644 --- a/internal/buffered/image_test.go +++ b/internal/buffered/image_test.go @@ -73,7 +73,7 @@ func TestMain(m *testing.M) { m: m, endCh: endCh, } - if err := ebiten.RunGame(g); err != nil && err != regularTermination { + if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) { panic(err) } diff --git a/internal/processtest/testdata/issue1753.go b/internal/processtest/testdata/issue1753.go index 249c2331a..7850b7e54 100644 --- a/internal/processtest/testdata/issue1753.go +++ b/internal/processtest/testdata/issue1753.go @@ -108,7 +108,7 @@ func (g *Game) Layout(width, height int) (int, int) { } func main() { - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2079.go b/internal/processtest/testdata/issue2079.go index 93b465937..ef0ffc86a 100644 --- a/internal/processtest/testdata/issue2079.go +++ b/internal/processtest/testdata/issue2079.go @@ -62,7 +62,7 @@ func (g *Game) Layout(width, height int) (int, int) { } func main() { - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2089.go b/internal/processtest/testdata/issue2089.go index de77d6da9..7c9bad6a4 100644 --- a/internal/processtest/testdata/issue2089.go +++ b/internal/processtest/testdata/issue2089.go @@ -72,7 +72,7 @@ func (g *Game) Layout(width, height int) (int, int) { } func main() { - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2129.go b/internal/processtest/testdata/issue2129.go index ceaf0bb60..c3e9cad9b 100644 --- a/internal/processtest/testdata/issue2129.go +++ b/internal/processtest/testdata/issue2129.go @@ -64,7 +64,7 @@ func (g *Game) Layout(width, height int) (int, int) { } func main() { - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2154_1.go b/internal/processtest/testdata/issue2154_1.go index cee3c6168..a4e94a59a 100644 --- a/internal/processtest/testdata/issue2154_1.go +++ b/internal/processtest/testdata/issue2154_1.go @@ -115,7 +115,7 @@ func (g *Game) Layout(width, height int) (int, int) { } func main() { - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2154_2.go b/internal/processtest/testdata/issue2154_2.go index acd8e796f..dce964e6a 100644 --- a/internal/processtest/testdata/issue2154_2.go +++ b/internal/processtest/testdata/issue2154_2.go @@ -86,7 +86,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func main() { ebiten.SetWindowTitle("Test") - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2162.go b/internal/processtest/testdata/issue2162.go index 619f1d9c2..2d40ccdf6 100644 --- a/internal/processtest/testdata/issue2162.go +++ b/internal/processtest/testdata/issue2162.go @@ -59,7 +59,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func main() { // Run a game loop at least for one frame to ensure the shader disposed. - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/processtest/testdata/issue2182.go b/internal/processtest/testdata/issue2182.go index a2d95b611..bcb7f1654 100644 --- a/internal/processtest/testdata/issue2182.go +++ b/internal/processtest/testdata/issue2182.go @@ -87,7 +87,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { func main() { ebiten.SetWindowTitle("Test") - if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination { + if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) { panic(err) } } diff --git a/internal/testing/testing.go b/internal/testing/testing.go index fb32284e3..6b1071353 100644 --- a/internal/testing/testing.go +++ b/internal/testing/testing.go @@ -46,7 +46,7 @@ func MainWithRunLoop(m *testing.M) { g := &game{ m: m, } - if err := ebiten.RunGame(g); err != nil && err != regularTermination { + if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) { panic(err) } os.Exit(g.code) diff --git a/run.go b/run.go index 4104403de..1f2e73c46 100644 --- a/run.go +++ b/run.go @@ -183,8 +183,10 @@ func (i *imageDumperGame) Layout(outsideWidth, outsideHeight int) (screenWidth, // TPS (ticks per second) is 60 by default. // This is not related to framerate (display's refresh rate). // -// RunGame returns error when 1) error happens in the underlying graphics driver, 2) audio error happens or -// 3) f returns error. In the case of 3), RunGame returns the same error. +// RunGame returns error when 1) an error happens in the underlying graphics driver, 2) an audio error happens +// or 3) f returns an error. In the case of 3), RunGame returns the same error so far, but it is recommended to +// use errors.Is when you check the returned error is the error you want, rather than comparing the values +// with == or != directly. // // The size unit is device-independent pixel. //