]> git.apps.os.sepia.ceph.com Git - fscrypt.git/commitdiff
cmd/fscrypt/errors: explicitly mark error messages as errors (#191)
authorEric Biggers <ebiggers@google.com>
Tue, 28 Jan 2020 09:58:51 +0000 (01:58 -0800)
committerJoseph Richey <joerichey@google.com>
Tue, 28 Jan 2020 09:58:51 +0000 (01:58 -0800)
When an fscrypt command fails and prints an error message, in some cases
it isn't clear that the message is actually an error, e.g.:

    fscrypt encrypt: login protectors do not need a name

Make it clear by always prefixing the message with "[ERROR] ", e.g.

    [ERROR] fscrypt encrypt: login protectors do not need a name

Update https://github.com/google/fscrypt/issues/186

cmd/fscrypt/errors.go

index 5239155681ae2d960329bfaa84775e96e9e6d6ae..bef6c2afba7cfb8e8145f44c2d8e9ff24628c70b 100644 (file)
@@ -169,12 +169,12 @@ func getErrorSuggestions(err error) string {
 }
 
 // newExitError creates a new error for a given context and normal error. The
-// returned error prepends the name of the relevant command and will make
-// fscrypt return a non-zero exit value.
+// returned error prepends an error tag and the name of the relevant command,
+// and it will make fscrypt return a non-zero exit value.
 func newExitError(c *cli.Context, err error) error {
-       // Prepend the full name and append suggestions (if any)
-       fullNamePrefix := getFullName(c) + ": "
-       message := fullNamePrefix + wrapText(err.Error(), utf8.RuneCountInString(fullNamePrefix))
+       // Prepend the error tag and full name, and append suggestions (if any)
+       prefix := "[ERROR] " + getFullName(c) + ": "
+       message := prefix + wrapText(err.Error(), utf8.RuneCountInString(prefix))
 
        if suggestion := getErrorSuggestions(err); suggestion != "" {
                message += "\n\n" + wrapText(suggestion, 0)