From b6e8ec50283ac2fbfc918bd964eadf6d86d83ccf Mon Sep 17 00:00:00 2001 From: Amolith Date: Fri, 31 Mar 2023 17:30:07 -0400 Subject: [PATCH] handle errors, yeet deprecated dep, & add license --- README.md | 6 ++++++ justfile | 27 +++++++++++++++++++++++++++ main.go | 16 +++++++++++++--- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 justfile diff --git a/README.md b/README.md index bf36620e1c9ca6c981a44096f5479268783c1ef7..a38a76c82736e176c6599c1945e2ad8c74f08bf5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ + + # p2c [![Go report card status][goreportcard-badge]][goreportcard] diff --git a/justfile b/justfile new file mode 100644 index 0000000000000000000000000000000000000000..ea8ddfba6c5d596e10077523ca979f89d8a72507 --- /dev/null +++ b/justfile @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: Amolith +# +# SPDX-License-Identifier: CC0-1.0 + +default: reuse lint test staticcheck + +reuse: + reuse lint + +lint: + # Linting Go code + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + golangci-lint run + +test: + # Running tests + go test -v ./... + +staticcheck: + # Performing static analysis + go install honnef.co/go/tools/cmd/staticcheck@latest + staticcheck ./... + +clean: + # Cleaning up + rm -rf p2c + diff --git a/main.go b/main.go index 5c54f4e4bd1a3d119ea763c9354f7123e27d523d..b4185b412d0a9b6ea9e984274da14827f89de6d2 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,6 @@ import ( "image" "image/color" "image/png" - "io/ioutil" "os" "strings" @@ -172,7 +171,12 @@ func main() { layout.Rigid(layout.Spacer{Height: 50}.Layout), ) }) - w.Frame(gtx.Ops) + err = w.Frame(gtx.Ops) + if err != nil { + fmt.Println("Error: Could not render GUI") + fmt.Println(err) + os.Exit(1) + } img := image.NewRGBA(image.Rectangle{Max: sz}) err = w.Screenshot(img) if err != nil { @@ -186,7 +190,13 @@ func main() { fmt.Println(err) os.Exit(1) } - ioutil.WriteFile(*flagOutput, buf.Bytes(), 0o644) + // Write the image to a file + err = os.WriteFile(*flagOutput, buf.Bytes(), 0o644) + if err != nil { + fmt.Println("Error: Could not write image to file") + fmt.Println(err) + os.Exit(1) + } os.Exit(0) }