File tree Expand file tree Collapse file tree 7 files changed +17
-13
lines changed Expand file tree Collapse file tree 7 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 1
1
package errorx
2
2
3
3
var (
4
- // General purpose errors to be used universally .
4
+ // CommonErrors is a namespace for general purpose errors designed for universal use .
5
5
// These errors should typically be used in opaque manner, implying no handing in user code.
6
6
// When handling is required, it is best to use custom error types with both standard and custom traits.
7
7
CommonErrors = NewNamespace ("common" )
Original file line number Diff line number Diff line change 1
1
package errorx
2
2
3
- // Modifier is a way to change a default behaviour for an error type, directly or via type hierarchy.
3
+ // TypeModifier is a way to change a default behaviour for an error type, directly or via type hierarchy.
4
4
// Modification is intentionally one-way, as it provides much more clarity.
5
5
// If there is a modifier on a type or a namespace, all its descendants definitely have the same default behaviour.
6
6
// If some of a subtypes must lack a specific modifier, then the modifier must be removed from the common ancestor.
7
7
type TypeModifier int
8
8
9
9
const (
10
- // An error type with such modifier creates transparent wrappers by default
10
+ // TypeModifierTransparent is a type modifier; an error type with such modifier creates transparent wrappers by default
11
11
TypeModifierTransparent TypeModifier = 1
12
- // An error type with such modifier omits the stack trace collection upon creation of an error instance
12
+ // TypeModifierOmitStackTrace is a type modifier; an error type with such modifier omits the stack trace collection upon creation of an error instance
13
13
TypeModifierOmitStackTrace TypeModifier = 2
14
14
)
15
15
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ type Namespace struct {
17
17
modifiers modifiers
18
18
}
19
19
20
- // Namespace itself is not comparable, so a key be used instead .
20
+ // NamespaceKey is a comparable descriptor of a Namespace .
21
21
type NamespaceKey struct {
22
22
id int64
23
23
name string
Original file line number Diff line number Diff line change @@ -18,12 +18,12 @@ func RegisterProperty(label string) Property {
18
18
return newProperty (label )
19
19
}
20
20
21
- // Context property, value is expected to be of context.Context type.
21
+ // PropertyContext is a context property, value is expected to be of context.Context type.
22
22
func PropertyContext () Property {
23
23
return propertyContext
24
24
}
25
25
26
- // Payload property, value may contain user defined structure with arbitrary data passed along with an error.
26
+ // PropertyPayload is a payload property, value may contain user defined structure with arbitrary data passed along with an error.
27
27
func PropertyPayload () Property {
28
28
return propertyPayload
29
29
}
Original file line number Diff line number Diff line change 9
9
"sync/atomic"
10
10
)
11
11
12
- // A used defined transformer for file path in stack trace output
12
+ // StackTraceFilePathTransformer is a used defined transformer for file path in stack trace output.
13
13
type StackTraceFilePathTransformer func (string ) string
14
14
15
15
// InitializeStackTraceTransformer provides a transformer to be used in formatting of all the errors.
Original file line number Diff line number Diff line change 1
1
package errorx
2
2
3
+ // CaseNoTrait is a synthetic type used in TypeSwitch, signifying a presence of non-nil error of some other type.
3
4
func NotRecognisedType () * Type { return notRecognisedType }
4
5
6
+ // CaseNoError is a synthetic trait used in TraitSwitch, signifying an absence of error.
5
7
func CaseNoError () Trait { return caseNoError }
8
+
9
+ // CaseNoTrait is a synthetic trait used in TraitSwitch, signifying a presence of non-nil error that lacks specified traits.
6
10
func CaseNoTrait () Trait { return caseNoTrait }
7
11
8
12
var (
@@ -43,7 +47,7 @@ func TypeSwitch(err error, types ...*Type) *Type {
43
47
// For error types that lack any of the provided traits, including non-errorx errors, CaseNoTrait() is returned.
44
48
// It is safe to treat CaseNoTrait() as 'any other kind of not-nil error' case.
45
49
// The effect is equivalent to a series of HasTrait() checks.
46
-
50
+ //
47
51
// NB: if more than one provided types matches the error, the first match in the providers list is recognised.
48
52
func TraitSwitch (err error , traits ... Trait ) Trait {
49
53
typed := Cast (err )
Original file line number Diff line number Diff line change @@ -26,16 +26,16 @@ func HasTrait(err error, key Trait) bool {
26
26
return typedErr .HasTrait (key )
27
27
}
28
28
29
- // A trait that signifies that an error is temporary in nature.
29
+ // Temporary is a trait that signifies that an error is temporary in nature.
30
30
func Temporary () Trait { return traitTemporary }
31
31
32
- // A trait that signifies that an error is some sort iof timeout.
32
+ // Timeout is a trait that signifies that an error is some sort iof timeout.
33
33
func Timeout () Trait { return traitTimeout }
34
34
35
- // A trait that marks such an error where the requested object is not found.
35
+ // NotFound is a trait that marks such an error where the requested object is not found.
36
36
func NotFound () Trait { return traitNotFound }
37
37
38
- // A trait that marks such an error where an update is failed as a duplicate.
38
+ // Duplicate is a trait that marks such an error where an update is failed as a duplicate.
39
39
func Duplicate () Trait { return traitDuplicate }
40
40
41
41
// IsTemporary checks for Temporary trait.
You can’t perform that action at this time.
0 commit comments