Debian Codegraph @

shoutrrr/cmd/exit_codes.go

raw
1 // Package cmd provides exit codes and result types for the Shoutrrr CLI.
2 package cmd
3
4 // ExitError contains the final exit message and code for a CLI session.
5 type ExitError struct {
6 // ExitCode is the numeric exit code returned to the operating system.
7 ExitCode int
8 // Message is the human-readable error message.
9 Message string
10 }
11
12 const (
13 // ExSuccess is the exit code that signals that everything went as expected.
14 ExSuccess = 0
15 // ExUsage is the exit code that signals that the application was not started with the correct arguments.
16 ExUsage = 64
17 // ExUnavailable is the exit code that signals that the application failed to perform the intended task.
18 ExUnavailable = 69
19 // ExConfig is the exit code that signals that the task failed due to a configuration error.
20 ExConfig = 78
21 )
22
23 // ErrNil is the empty ExitError that is used whenever the command ran successfully.
24 var ErrNil = ExitError{
25 ExitCode: 0,
26 Message: "",
27 }
28
29 // Error returns the error message for the ExitError.
30 // This implements the error interface.
31 func (e ExitError) Error() string {
32 return e.Message
33 }
34
35 // InvalidUsage returns an ExitError with the exit code ExUsage.
36 //
37 // Parameters:
38 // - message: The error message describing the invalid usage.
39 //
40 // Returns:
41 // - ExitError: An ExitError with ExitCode set to ExUsage.
42 func InvalidUsage(message string) ExitError {
43 return ExitError{
44 ExUsage,
45 message,
46 }
47 }
48
49 // TaskUnavailable returns an ExitError with the exit code ExUnavailable.
50 //
51 // Parameters:
52 // - message: The error message describing why the task was unavailable.
53 //
54 // Returns:
55 // - ExitError: An ExitError with ExitCode set to ExUnavailable.
56 func TaskUnavailable(message string) ExitError {
57 return ExitError{
58 ExUnavailable,
59 message,
60 }
61 }
62
63 // ConfigurationError returns an ExitError with the exit code ExConfig.
64 //
65 // Parameters:
66 // - message: The error message describing the configuration error.
67 //
68 // Returns:
69 // - ExitError: An ExitError with ExitCode set to ExConfig.
70 func ConfigurationError(message string) ExitError {
71 return ExitError{
72 ExConfig,
73 message,
74 }
75 }