aboutsummaryrefslogtreecommitdiff
path: root/internal/exitcodes/exitcodes.go
blob: 2ec3ae6db91ab20d1eb76e2a2fa1a5a1416f6480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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
	// PasswordIncorrect - the password was incorrect
	PasswordIncorrect = 12
	// TODO several other exit codes are defined in main.go. These will be
	// ported over here.
)

// Err wraps an error with an associated numeric exit code
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,
	}
}

// Exit extracts the numeric exit code from "err" (if available) and exits the
// application.
func Exit(err error) {
	err2, ok := err.(Err)
	if !ok {
		os.Exit(Other)
	}
	os.Exit(err2.code)
}