git » chasquid » commit b0877f0

chasquid-util: Print errors to stderr

author Alberto Bertogli
2024-03-04 19:29:24 UTC
committer Alberto Bertogli
2024-03-07 23:07:37 UTC
parent 8e1fd524420a93e93c83f90d9cc1d170916c1f19

chasquid-util: Print errors to stderr

To make it more difficult to accidentally supress errors, or mistake them
for legitimate output, print errors to stderr.

cmd/chasquid-util/chasquid-util.go +3 -2
cmd/chasquid-util/test.sh +4 -4

diff --git a/cmd/chasquid-util/chasquid-util.go b/cmd/chasquid-util/chasquid-util.go
index e3c68a8..8325e17 100644
--- a/cmd/chasquid-util/chasquid-util.go
+++ b/cmd/chasquid-util/chasquid-util.go
@@ -96,9 +96,10 @@ func main() {
 	}
 }
 
-// Fatalf prints the given message, then exits the program with an error code.
+// Fatalf prints the given message to stderr, then exits the program with an
+// error code.
 func Fatalf(s string, arg ...interface{}) {
-	fmt.Printf(s+"\n", arg...)
+	fmt.Fprintf(os.Stderr, s+"\n", arg...)
 	os.Exit(1)
 }
 
diff --git a/cmd/chasquid-util/test.sh b/cmd/chasquid-util/test.sh
index 0fdc9dc..6b01665 100755
--- a/cmd/chasquid-util/test.sh
+++ b/cmd/chasquid-util/test.sh
@@ -40,7 +40,7 @@ if ! r user-add denied@domain --receive_only > /dev/null; then
 fi
 check_userdb
 
-if r user-add xxx@domain --password=passwd --receive_only > /dev/null; then
+if r user-add xxx@domain --password=passwd --receive_only > /dev/null 2>&1; then
 	echo user-add --password --receive_only worked
 	exit 1
 fi
@@ -50,12 +50,12 @@ if ! r authenticate user@domain --password=passwd > /dev/null; then
 	exit 1
 fi
 
-if r authenticate user@domain --password=abcd > /dev/null; then
+if r authenticate user@domain --password=abcd > /dev/null 2>&1; then
 	echo authenticate with bad password worked
 	exit 1
 fi
 
-if r authenticate denied@domain --password=abcd > /dev/null; then
+if r authenticate denied@domain --password=abcd > /dev/null 2>&1; then
 	echo authenticate on a no-submission user worked
 	exit 1
 fi
@@ -82,7 +82,7 @@ if ! r user-remove user@domain > /dev/null; then
 fi
 check_userdb
 
-if r authenticate user@domain --password=passwd > /dev/null; then
+if r authenticate user@domain --password=passwd > /dev/null 2>&1; then
 	echo authenticate for removed user worked
 	exit 1
 fi