From 896487621792d9468b2d5f7c192f8403539724cc Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 19 Dec 2018 08:18:28 +0100 Subject: [PATCH] error msgs: Add punctuations when needed (#2628) This commit will automatically add ':' or '.' after scanning the generic and the detail error messages. This will simplify maintaining error messages. --- cmd/error.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cmd/error.go b/cmd/error.go index f4572e42..fd51dbad 100644 --- a/cmd/error.go +++ b/cmd/error.go @@ -19,6 +19,8 @@ package cmd import ( "encoding/json" "fmt" + "strings" + "unicode" "github.com/minio/cli" "github.com/minio/mc/pkg/console" @@ -75,11 +77,35 @@ func fatal(err *probe.Error, msg string, data ...interface{}) { console.Println(string(json)) console.Fatalln() } + msg = fmt.Sprintf(msg, data...) + errmsg := err.String() if !globalDebug { - console.Fatalln(fmt.Sprintf("%s %s", msg, err.ToGoError())) + errmsg = err.ToGoError().Error() } - console.Fatalln(fmt.Sprintf("%s %s", msg, err)) + + // Remove unnecessary leading spaces in generic/detailed error messages + msg = strings.TrimSpace(msg) + errmsg = strings.TrimSpace(errmsg) + + // Add punctuations when needed + if len(errmsg) > 0 && len(msg) > 0 { + if msg[len(msg)-1] != ':' && msg[len(msg)-1] != '.' { + // The detailed error message starts with a capital letter, + // we should then add '.', otherwise add ':'. + if unicode.IsUpper(rune(errmsg[0])) { + msg += "." + } else { + msg += ":" + } + } + // Add '.' to the detail error if not found + if errmsg[len(errmsg)-1] != '.' { + errmsg += "." + } + } + + console.Fatalln(fmt.Sprintf("%s %s", msg, errmsg)) } // Exit coder wraps cli new exit error with a