forked from zorchenhimer/MovieNight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
60 lines (47 loc) · 1.37 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
package main
import (
"fmt"
"reflect"
"strings"
)
func errorName(err error) string {
return reflect.ValueOf(err).Type().Name()
}
type ChatError struct {
msg string
}
func (e ChatError) Error() string {
return e.msg
}
func newChatError(s string, a ...interface{}) error {
return ChatError{msg: fmt.Sprintf(s, a...)}
}
// UserNameError is a base error for errors that deal with user names
type UserNameError struct {
Name string
}
// UserFormatError is an error for when the name format does not match what is required
type UserFormatError UserNameError
func (e UserFormatError) Error() string {
return fmt.Sprintf("\"%s\", is in an invalid format", e.Name)
}
// UserTakenError is an error for when a user tries to join with a name that is already taken
type UserTakenError UserNameError
func (e UserTakenError) Error() string {
return fmt.Sprintf("\"%s\", is already taken", e.Name)
}
// BannedUserError is an error for when a user tries to join with a banned ip address
type BannedUserError struct {
Host, Name string
Names []string
}
func (e BannedUserError) Error() string {
return fmt.Sprintf("banned user tried to connect with IP %s: %s (banned with name(s) %s)", e.Host, e.Name, strings.Join(e.Names, ", "))
}
func newBannedUserError(host, name string, names []string) BannedUserError {
return BannedUserError{
Host: host,
Name: name,
Names: names,
}
}