From 3ccd4d07e98c6bf8eb962b4ca7099369a9d65dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Mon, 1 Feb 2021 10:34:06 +0100 Subject: [PATCH 1/2] fix: accidentally overwritten error value In function _cli.send_ the named return value 'err' gets accidentally overwritten in the deferred anonymous function that removes the files/directories. Renamed the error variable inside the deferred function so that it does not overwrite the original error anymore. Closes #296 --- src/cli/cli.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 0c5bc2b1..b70e1f02 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -223,9 +223,9 @@ func send(c *cli.Context) (err error) { return } defer func() { - err = os.Remove(fnames[0]) - if err != nil { - log.Error(err) + e := os.Remove(fnames[0]) + if e != nil { + log.Error(e) } }() } else if c.String("text") != "" { @@ -234,9 +234,9 @@ func send(c *cli.Context) (err error) { return } defer func() { - err = os.Remove(fnames[0]) - if err != nil { - log.Error(err) + e := os.Remove(fnames[0]) + if e != nil { + log.Error(e) } }() From 0b60fef24620e813eb387f37fc8dfb7344157985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Mon, 1 Feb 2021 10:48:34 +0100 Subject: [PATCH 2/2] refactor: write errors into stderr and add exit code Instead of writing errors into stdout and alway returning exit code 0, we now write into stderr and return exit code 1 in case that an error occured. --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 4c442fb3..a3a9f4e3 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ package main //go:generate git tag -af v$VERSION -m "v$VERSION" import ( - "fmt" + "log" "github.com/schollz/croc/v8/src/cli" ) @@ -28,6 +28,6 @@ func main() { // } // }() if err := cli.Run(); err != nil { - fmt.Println(err) + log.Fatalln(err) } }