Skip to content

Commit f12f730

Browse files
committed
add specific status code for sops errors
1 parent 7051ccd commit f12f730

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmd/sops/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ func toExitError(err error) error {
10061006
return cliErr
10071007
} else if execErr, ok := err.(*osExec.ExitError); ok && execErr != nil {
10081008
return cli.NewExitError(err, execErr.ExitCode())
1009+
} else if sopsErr, ok := err.(*sops.SopsError); ok && sopsErr != nil {
1010+
return cli.NewExitError(err, sopsErr.ExitCode())
10091011
} else if err != nil {
10101012
return cli.NewExitError(err, codes.ErrorGeneric)
10111013
}

sops.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,24 @@ import (
5858
// DefaultUnencryptedSuffix is the default suffix a TreeItem key has to end with for sops to leave its Value unencrypted
5959
const DefaultUnencryptedSuffix = "_unencrypted"
6060

61-
type sopsError string
61+
type SopsError struct {
62+
exitCode int
63+
message string
64+
}
65+
66+
func (e SopsError) ExitCode() int {
67+
return e.exitCode
68+
}
6269

63-
func (e sopsError) Error() string {
64-
return string(e)
70+
func (e SopsError) Error() string {
71+
return e.message
6572
}
6673

6774
// MacMismatch occurs when the computed MAC does not match the expected ones
68-
const MacMismatch = sopsError("MAC mismatch")
75+
var MacMismatch = &SopsError{10, "MAC mismatch"}
6976

7077
// MetadataNotFound occurs when the input file is malformed and doesn't have sops metadata in it
71-
const MetadataNotFound = sopsError("sops metadata not found")
78+
var MetadataNotFound = &SopsError{11, "sops metadata not found"}
7279

7380
var log *logrus.Logger
7481

0 commit comments

Comments
 (0)