-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
72 lines (57 loc) · 1.58 KB
/
errors.go
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
69
70
71
72
package commanderrors
import (
"fmt"
"github.com/Postcord/router"
)
// CommandError is an error that is returned when a command fails
type CommandError interface {
Error() string
Command() string
}
// ErrRuntime represents a generic runtime error
type ErrRuntime struct {
cmd *router.Command
Value string
}
func NewErrRuntime(command *router.Command, value string) *ErrRuntime {
return &ErrRuntime{
cmd: command,
Value: value,
}
}
func (e *ErrRuntime) Error() string {
return fmt.Sprintf("Error (%s): %s", e.Command(), e.Value)
}
func (e *ErrRuntime) Command() string {
return e.cmd.Name
}
// ErrCommandNotImplemented is an error that is returned when a command is not implemented
type ErrCommandNotImplemented struct {
cmd *router.Command
}
func NewErrCommandNotImplemented(command *router.Command) *ErrCommandNotImplemented {
return &ErrCommandNotImplemented{
cmd: command,
}
}
func (e *ErrCommandNotImplemented) Error() string {
return fmt.Sprintf("Command %s not implemented", e.Command())
}
func (e *ErrCommandNotImplemented) Command() string {
return e.cmd.Name
}
// ErrCommandNotAllowed is an error that is returned when the running user is not currently allowed to run a command
type ErrCommandNotAllowed struct {
cmd *router.Command
}
func NewErrCommandNotAllowed(command *router.Command) *ErrCommandNotAllowed {
return &ErrCommandNotAllowed{
cmd: command,
}
}
func (e *ErrCommandNotAllowed) Error() string {
return fmt.Sprintf("You are not allowed to run %s at this time.", e.Command())
}
func (e *ErrCommandNotAllowed) Command() string {
return e.cmd.Name
}