From b0877f0866fac1961a8bf0a8154bcb8a6d283cd3 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Mon, 4 Mar 2024 19:29:24 +0000 Subject: [PATCH] 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 | 5 +++-- cmd/chasquid-util/test.sh | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) 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