From 6326c271aeedeaf3721e50a596107b85e5187f9a Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 12 Sep 2024 12:32:42 +0100 Subject: [PATCH 1/2] .github/go: run errcheck in all subpackages --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9355d34..9aae754 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,7 +30,7 @@ jobs: run: go run honnef.co/go/tools/cmd/staticcheck@2023.1.7 ./... - name: Errcheck - run: go run github.com/kisielk/errcheck@v1.7.0 -ignoretests ./ ./event + run: go run github.com/kisielk/errcheck@v1.7.0 -ignoretests ./... - name: Build run: go build -v ./... From 58a4efb0a67520f546cd332cd4d25edf7fc508b2 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 12 Sep 2024 12:34:01 +0100 Subject: [PATCH 2/2] examples: fix errcheck issues --- examples/events/events.go | 12 +++++++++--- examples/hyprctl/main.go | 36 ++++++++++++++++++------------------ examples/hyprtabs/main.go | 4 ++-- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/examples/events/events.go b/examples/events/events.go index 4169551..31d8665 100644 --- a/examples/events/events.go +++ b/examples/events/events.go @@ -13,6 +13,12 @@ type ev struct { event.DefaultEventHandler } +func must(err error) { + if err != nil { + panic(err) + } +} + func (e *ev) Workspace(w event.WorkspaceName) { fmt.Printf("Workspace: %+v\n", w) } @@ -29,15 +35,15 @@ func main() { defer cancel() c := event.MustClient() - defer c.Close() + defer must(c.Close()) // Will listen for events for 5 seconds and exit - c.Subscribe( + must(c.Subscribe( ctx, &ev{}, event.EventWorkspace, event.EventActiveWindow, - ) + )) fmt.Println("Bye!") } diff --git a/examples/hyprctl/main.go b/examples/hyprctl/main.go index 021287f..fa1446e 100644 --- a/examples/hyprctl/main.go +++ b/examples/hyprctl/main.go @@ -51,9 +51,9 @@ func mustMarshalIndent(v any) []byte { } func usage(m map[string]func(args []string)) { - fmt.Fprintf(out, "Usage of %s:\n", os.Args[0]) - fmt.Fprintf(out, " %s [subcommand] \n\n", os.Args[0]) - fmt.Fprintf(out, "Available subcommands:\n") + must1(fmt.Fprintf(out, "Usage of %s:\n", os.Args[0])) + must1(fmt.Fprintf(out, " %s [subcommand] \n\n", os.Args[0])) + must1(fmt.Fprintf(out, "Available subcommands:\n")) // Sort keys before printing, since Go randomises order subcommands := make([]string, len(m)) @@ -64,7 +64,7 @@ func usage(m map[string]func(args []string)) { } sort.Strings(subcommands) for _, s := range subcommands { - fmt.Fprintf(out, " - %s\n", s) + must1(fmt.Fprintf(out, " - %s\n", s)) } } @@ -88,16 +88,16 @@ func main() { m := map[string]func(args []string){ "activewindow": func(_ []string) { v := must1(c.ActiveWindow()) - fmt.Printf("%s\n", mustMarshalIndent(v)) + must1(fmt.Printf("%s\n", mustMarshalIndent(v))) }, "activeworkspace": func(_ []string) { v := must1(c.ActiveWorkspace()) - fmt.Printf("%s\n", mustMarshalIndent(v)) + must1(fmt.Printf("%s\n", mustMarshalIndent(v))) }, "batch": func(args []string) { - batchFS.Parse(args) + must(batchFS.Parse(args)) if len(batch) == 0 { - fmt.Fprintf(out, "Error: at least one '-c' is required for batch.\n") + must1(fmt.Fprintf(out, "Error: at least one '-c' is required for batch.\n")) os.Exit(1) } else { // Batch commands are done in the following way: @@ -106,35 +106,35 @@ func main() { fmt.Sprintf("[[BATCH]]%s", strings.Join(batch, ";")), ) v := must1(c.RawRequest(r)) - fmt.Printf("%s\n", v) + must1(fmt.Printf("%s\n", v)) } }, "dispatch": func(args []string) { - dispatchFS.Parse(args) + must(dispatchFS.Parse(args)) if len(dispatch) == 0 { - fmt.Fprintf(out, "Error: at least one '-c' is required for dispatch.\n") + must1(fmt.Fprintf(out, "Error: at least one '-c' is required for dispatch.\n")) os.Exit(1) } else { v := must1(c.Dispatch(dispatch...)) - fmt.Printf("%s\n", v) + must1(fmt.Printf("%s\n", v)) } }, "kill": func(_ []string) { v := must1(c.Kill()) - fmt.Printf("%s\n", v) + must1(fmt.Printf("%s\n", v)) }, "reload": func(_ []string) { v := must1(c.Reload()) - fmt.Printf("%s\n", v) + must1(fmt.Printf("%s\n", v)) }, "setcursor": func(_ []string) { - setcursorFS.Parse(os.Args[2:]) + must(setcursorFS.Parse(os.Args[2:])) v := must1(c.SetCursor(*theme, *size)) - fmt.Printf("%s\n", v) + must1(fmt.Printf("%s\n", v)) }, "version": func(_ []string) { v := must1(c.Version()) - fmt.Printf("%s\n", mustMarshalIndent(v)) + must1(fmt.Printf("%s\n", mustMarshalIndent(v))) }, } @@ -151,7 +151,7 @@ func main() { c = hyprland.MustClient() run(os.Args[2:]) } else { - fmt.Fprintf(out, "Error: unknown subcommand: %s\n", subcommand) + must1(fmt.Fprintf(out, "Error: unknown subcommand: %s\n", subcommand)) os.Exit(1) } } diff --git a/examples/hyprtabs/main.go b/examples/hyprtabs/main.go index 5ed943a..6d37470 100644 --- a/examples/hyprtabs/main.go +++ b/examples/hyprtabs/main.go @@ -28,12 +28,12 @@ func main() { aWindow := must1(client.ActiveWindow()) if len(aWindow.Grouped) > 0 { - client.Dispatch( + must1(client.Dispatch( // If we are already in a group, ungroup "togglegroup", // Make the current window as master (when using master layout) "layoutmsg swapwithmaster master", - ) + )) } else { var cmdbuf []string aWorkspace := must1(client.ActiveWorkspace())