summaryrefslogtreecommitdiff
path: root/internal/exitcodes/exitcodes.go
blob: 7a2efdb0e633ca57559e05e3d940863b19a026b9 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Package exitcodes contains all well-defined exit codes that gocryptfs
// can return.
package exitcodes

import (
	"fmt"
	"os"
)

const (
	// Usage error: cli syntax etc
	Usage = 1
	// 2 is reserved because it is used by Go panic

	// Mount is an error on mount
	Mount = 3
	// CipherDir means that the CIPHERDIR does not exist
	CipherDir = 6
	// Init is an error on filesystem init
	Init = 7
	// LoadConf is an error while loading gocryptfs.conf
	LoadConf = 8
	// ReadPassword means something went wrong reading the password
	ReadPassword = 9
	// MountPoint error means that the mountpoint is invalid (not empty etc).
	MountPoint = 10
	// Other error - please inspect the message
	Other = 11
	// PasswordIncorrect - the password was incorrect
	PasswordIncorrect = 12
	// ScryptParams means that scrypt was called with invalid parameters
	ScryptParams = 13
	// MasterKey means that something went wrong when parsing the "-masterkey"
	// command line option
	MasterKey = 14
	// SigInt means we got SIGINT
	SigInt = 15
	// PanicLog means the panic log was not empty when we were unmounted
	PanicLog = 16
	// ForkChild means forking the worker child failed
	ForkChild = 17
	// OpenSSL means you tried to enable OpenSSL, but we were compiled without it.
	OpenSSL = 18
)

// 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)
}