This repository has been archived by the owner on Jan 9, 2022. It is now read-only.
/
errors.go
96 lines (76 loc) · 2.22 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2016 Arsham Shirvani <arshamshirvani@gmail.com>. All rights reserved.
// Use of this source code is governed by the Apache 2.0 license
// License that can be found in the LICENSE file.
package config
import "fmt"
// ErrEmptyConfig is returned when the config file is empty.
var ErrEmptyConfig = &StructureErr{"", "empty configuration file", nil}
const (
// NilStr is used to print nil string for an error.
NilStr = "<nil>"
)
// StructureErr is for reading the configuration file errors.
type StructureErr struct {
Section string // The section that error happened
Reason string // The reason behind the error
Err error // Err is the occurred error during the operation.
}
// Error returns "<nil>" if the error is nil.
func (e *StructureErr) Error() string {
if e == nil {
return NilStr
}
s := e.Section
if e.Reason != "" {
s += " " + e.Reason
}
if e.Err != nil {
s += ": " + e.Err.Error()
}
return s
}
// NotSpecifiedError is returned when a section is not specified.
type NotSpecifiedError StructureErr
// NewNotSpecifiedError returns ErrNotSpecified with the given input.
func NewNotSpecifiedError(section, reason string, err error) *NotSpecifiedError {
return &NotSpecifiedError{section, reason, err}
}
func (e *NotSpecifiedError) Error() string {
if e == nil {
return NilStr
}
s := e.Section
if e.Reason != "" {
s += " " + e.Reason
}
s += " not specified"
if e.Err != nil {
s += ": " + e.Err.Error()
}
return s
}
// RoutersError is returned when routes are not configured correctly.
// The section on this error is the subsection of the route.
type RoutersError struct{ StructureErr }
// NewRoutersError instantiates an RoutersError with the given input.
func NewRoutersError(section, reason string, err error) *RoutersError {
return &RoutersError{StructureErr{section, reason, err}}
}
func (e *RoutersError) Error() string {
if e == nil {
return NilStr
}
s := "not specified: " + e.Section
if e.Reason != "" {
s += " " + e.Reason
}
if e.Err != nil {
s += ": " + e.Err.Error()
}
return s
}
// NotSupportedError says something is still not supported.
type NotSupportedError string
func (n NotSupportedError) Error() string {
return fmt.Sprintf("%s is not supported", string(n))
}