aboutsummaryrefslogtreecommitdiff
path: root/internal/exitcodes
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-02-26 19:25:23 +0100
committerJakob Unterwurzacher2017-02-26 19:25:23 +0100
commit427c6c17193eda7fec77490175fbf7d8c86c3481 (patch)
treee8cca03fa6f28518d462dff785823d3141e66b14 /internal/exitcodes
parent57612a278bdd26de611b543be311748ca4dc42ca (diff)
exitcodes: define code 12 for "password incorrect"
Diffstat (limited to 'internal/exitcodes')
-rw-r--r--internal/exitcodes/exitcodes.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/exitcodes/exitcodes.go b/internal/exitcodes/exitcodes.go
new file mode 100644
index 0000000..908e714
--- /dev/null
+++ b/internal/exitcodes/exitcodes.go
@@ -0,0 +1,38 @@
+// Package exitcodes contains all well-defined exit codes that gocryptfs
+// can return.
+package exitcodes
+
+import (
+ "fmt"
+ "os"
+)
+
+const (
+ // Other error - please inspect the message
+ Other = 11
+ // The password was incorrect
+ PasswordIncorrect = 12
+ // TODO several other exit codes are defined in main.go. These will be
+ // ported over here.
+)
+
+type Err struct {
+ error
+ code int
+}
+
+// NewErr returns an error containing "msg" and the exit code "code".
+func NewErr(msg string, code int) Err {
+ return Err{
+ error: fmt.Errorf(msg),
+ code: code,
+ }
+}
+
+func Exit(err error) {
+ err2, ok := err.(Err)
+ if !ok {
+ os.Exit(Other)
+ }
+ os.Exit(err2.code)
+}