summaryrefslogtreecommitdiff
path: root/errors.go
blob: 01f8310029d0a7809e2e11731df345af922d9fc3 (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
package argvpb

import "fmt"

// This file defines the set of conventional exit codes for command-line applications,
// These are the standard and common GNU/Linux and BSD `sysexits.h` best practices

type ExitCode int

const (
	ExitSuccess     ExitCode = 0      // the program completed its task without errors.
	ExitFailure     ExitCode = 1      // generic, catch-all code for "something went wrong."
	ExitUsage       ExitCode = 64     // EX_USAGE:       user provided invalid command-line arguments or flags.
	ExitDataErr     ExitCode = 65     // EX_DATAERR:     input data was incorrect or malformed.
	ExitNoInput     ExitCode = 66     // EX_NOINPUT:     an input file was not found or could not be read.
	ExitNoUser      ExitCode = 67     // EX_NOUSER:      a specified user did not exist.
	ExitNoHost      ExitCode = 68     // EX_NOHOST:      a specified host did not exist.
	ExitUnavailable ExitCode = 69     // EX_UNAVAILABLE: a required service is unavailable.
	ExitSoftware    ExitCode = 70     // EX_SOFTWARE:    internal software error. bugs ("this should never happen")
	ExitOSErr       ExitCode = 71     // EX_OSERR:       an operating system error, such as a failed system call.
	ExitOSFile      ExitCode = 72     // EX_OSFILE:      a critical OS file is missing or corrupt. (e.g., /etc/passwd)
	ExitCantCreate  ExitCode = 73     // EX_CANTCREATE:  a user-specified output file could not be created.
	ExitIOErr       ExitCode = 74     // EX_IOERR:       an error occurred during an I/O operation.
	ExitTempFail    ExitCode = 75     // EX_TEMPFAIL:    temporary failure. The user is invited to retry.
	ExitProtocol    ExitCode = 76     // EX_PROTOCOL:    protocol error during network communication.
	ExitNoPerm      ExitCode = 77     // EX_NOPERM:      the user does not have sufficient filesystem permissions.
	ExitConfig      ExitCode = 78     // EX_CONFIG:      something is wrong in a configuration file.
	Exit126         ExitCode = 126    // Reserved for shell (command not executable)
	Exit127         ExitCode = 127    // Reserved for shell (command not found)
	Exit128         ExitCode = 128    // Reserved for shell (termination by a signal)
	ExitPB          ExitCode = 252525 // NEW FOR ARGV:   return a protobuf on exit. todo: need someone to make an RFC for this
	Exit109         ExitCode = 109    // for testing argv. 109 = 252525 % 256
)

// todo: finish this struct
func (x ExitCode) String() string {
	switch x {
	case ExitSuccess:
		return "ExitSuccess"
	case ExitFailure:
		return "ExitFailure"
	case ExitUsage:
		return "invalid command-line arguments or flags."
	case ExitDataErr:
		return "the input data was incorrect or malformed."
	case ExitNoInput:
		return "the input file not found, could not be read"
	case ExitPB:
		return "In the year 252525, the backwards time-machine still won't have arrived"
	}
	return fmt.Sprintf("%d", x)
}