Skip to content

Commit e4c69bf

Browse files
committed
fix dogoc comments
1 parent a86349f commit e4c69bf

3 files changed

Lines changed: 57 additions & 56 deletions

File tree

type.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"encoding"
55
)
66

7-
// A distinct error type
8-
// Belongs to a namespace, may be a descendant of another type in the same namespace
9-
// May contain or inherit modifiers that alter the default properties for any error of this type
10-
// May contain or inherit traits that all errors of this type will possess
7+
// Type is a distinct error type.
8+
// Belongs to a namespace, may be a descendant of another type in the same namespace.
9+
// May contain or inherit modifiers that alter the default properties for any error of this type.
10+
// May contain or inherit traits that all errors of this type will possess.
1111
type Type struct {
1212
namespace Namespace
1313
parent *Type
@@ -19,62 +19,62 @@ type Type struct {
1919

2020
var _ encoding.TextMarshaler = (*Type)(nil)
2121

22-
// Defines a new distinct type within a namespace
22+
// NewType defines a new distinct type within a namespace.
2323
func NewType(namespace Namespace, name string, traits ...Trait) *Type {
2424
return newType(namespace, nil, name, traits...)
2525
}
2626

27-
// Defines a new subtype within a namespace of a parent type
27+
// NewSubtype defines a new subtype within a namespace of a parent type.
2828
func (t *Type) NewSubtype(name string, traits ...Trait) *Type {
2929
return newType(t.namespace, t, name, traits...)
3030
}
3131

32-
// One-time modification of defaults in error creation
32+
// ApplyModifiers makes a one-time modification of defaults in error creation.
3333
func (t *Type) ApplyModifiers(modifiers ...TypeModifier) *Type {
3434
t.modifiers = t.modifiers.ReplaceWith(newTypeModifiers(modifiers...))
3535
return t
3636
}
3737

38-
// Create an error of this type with a message
39-
// Without args, leaves the original message intact, so a message may be generated or provided externally
40-
// With args, a formatting is performed, and it is therefore expected a format string to be constant
38+
// New creates an error of this type with a message.
39+
// Without args, leaves the original message intact, so a message may be generated or provided externally.
40+
// With args, a formatting is performed, and it is therefore expected a format string to be constant.
4141
func (t *Type) New(message string, args ...interface{}) *Error {
4242
return NewErrorBuilder(t).
4343
WithConditionallyFormattedMessage(message, args...).
4444
Create()
4545
}
4646

47-
// Create an error of this type without any message
48-
// May be used when other information is sufficient, such as error type and stack trace
47+
// NewWithNoMessage creates an error of this type without any message.
48+
// May be used when other information is sufficient, such as error type and stack trace.
4949
func (t *Type) NewWithNoMessage() *Error {
5050
return NewErrorBuilder(t).
5151
Create()
5252
}
5353

54-
// Create an error of this type with another as original cause
55-
// As far as type checks are concerned, this error is the only one visible, with original present only in error message
56-
// The original error will, however, pass its dynamic properties
57-
// Without args, leaves the original message intact, so a message may be generated or provided externally
58-
// With args, a formatting is performed, and it is therefore expected a format string to be constant
54+
// Wrap creates an error of this type with another as original cause.
55+
// As far as type checks are concerned, this error is the only one visible, with original present only in error message.
56+
// The original error will, however, pass its dynamic properties.
57+
// Without args, leaves the original message intact, so a message may be generated or provided externally.
58+
// With args, a formatting is performed, and it is therefore expected a format string to be constant.
5959
func (t *Type) Wrap(err error, message string, args ...interface{}) *Error {
6060
return NewErrorBuilder(t).
6161
WithConditionallyFormattedMessage(message, args...).
6262
WithCause(err).
6363
Create()
6464
}
6565

66-
// Create an error of this type with another as original cause and with no additional message
67-
// May be used when other information is sufficient, such as error type, cause and its stack trace and message
68-
// As far as type checks are concerned, this error is the only one visible, with original visible only in error message
69-
// The original error will, however, pass its dynamic properties
66+
// WrapWithNoMessage creates an error of this type with another as original cause and with no additional message.
67+
// May be used when other information is sufficient, such as error type, cause and its stack trace and message.
68+
// As far as type checks are concerned, this error is the only one visible, with original visible only in error message.
69+
// The original error will, however, pass its dynamic properties.
7070
func (t *Type) WrapWithNoMessage(err error) *Error {
7171
return NewErrorBuilder(t).
7272
WithCause(err).
7373
Create()
7474
}
7575

76-
// Type check for errors
77-
// Returns true either both are exactly the same type, or if the same is true for one of current type's ancestors
76+
// IsOfType is a type check for error.
77+
// Returns true either both are exactly the same type, or if the same is true for one of current type's ancestors.
7878
func (t *Type) IsOfType(other *Type) bool {
7979
current := t
8080
for current != nil {
@@ -88,25 +88,25 @@ func (t *Type) IsOfType(other *Type) bool {
8888
return false
8989
}
9090

91-
// Type check for errors
92-
// Returns true either both are exactly the same type, or if the same is true for one of current type's ancestors
93-
// For an error that does not have an errorx type, returns false
91+
// IsOfType is a type check for errors.
92+
// Returns true either both are exactly the same type, or if the same is true for one of current type's ancestors.
93+
// For an error that does not have an errorx type, returns false.
9494
func IsOfType(err error, t *Type) bool {
9595
e := Cast(err)
9696
return e != nil && e.IsOfType(t)
9797
}
9898

99-
// A parent type, if present
99+
// Supertype returns a parent type, if present.
100100
func (t *Type) Supertype() *Type {
101101
return t.parent
102102
}
103103

104-
// A fully qualified name if type, is not presumed to be unique, see TypeSubscriber
104+
// FullName returns a fully qualified name if type, is not presumed to be unique, see TypeSubscriber.
105105
func (t *Type) FullName() string {
106106
return t.fullName
107107
}
108108

109-
// A base namespace this type belongs to
109+
// RootNamespace returns a base namespace this type belongs to.
110110
func (t *Type) RootNamespace() Namespace {
111111
return t.namespace
112112
}

utils.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package errorx
22

3-
// Attempts to cast an error to errorx Type, returns nil if cast has failed
3+
// Cast attempts to cast an error to errorx Type, returns nil if cast has failed.
44
func Cast(err error) *Error {
55
if e, ok := err.(*Error); ok && e != nil {
66
return e
@@ -9,8 +9,8 @@ func Cast(err error) *Error {
99
return nil
1010
}
1111

12-
// Returns nil if an error is of one of the provided types, returns the provided error otherwise
13-
// May be used if a particular error signifies a mark in control flow rather than an error to be reported to the caller
12+
// Ignore returns nil if an error is of one of the provided types, returns the provided error otherwise.
13+
// May be used if a particular error signifies a mark in control flow rather than an error to be reported to the caller.
1414
func Ignore(err error, types ...*Type) error {
1515
if e := Cast(err); e != nil {
1616
for _, t := range types {
@@ -23,8 +23,8 @@ func Ignore(err error, types ...*Type) error {
2323
return err
2424
}
2525

26-
// Returns nil if an error has one of the provided traits, returns the provided error otherwise
27-
// May be used if a particular error trait signifies a mark in control flow rather than an error to be reported to the caller
26+
// IgnoreWithTrait returns nil if an error has one of the provided traits, returns the provided error otherwise.
27+
// May be used if a particular error trait signifies a mark in control flow rather than an error to be reported to the caller.
2828
func IgnoreWithTrait(err error, traits ...Trait) error {
2929
if e := Cast(err); e != nil {
3030
for _, t := range traits {
@@ -37,8 +37,8 @@ func IgnoreWithTrait(err error, traits ...Trait) error {
3737
return err
3838
}
3939

40-
// Returns the full type name if an error; returns an empty string for non-errorx error
41-
// For decorated errors, the type of an original cause is used
40+
// GetTypeName returns the full type name if an error; returns an empty string for non-errorx error.
41+
// For decorated errors, the type of an original cause is used.
4242
func GetTypeName(err error) string {
4343
if e := Cast(err); e != nil {
4444
t := e.Type()
@@ -50,8 +50,8 @@ func GetTypeName(err error) string {
5050
return ""
5151
}
5252

53-
// A utility function to duplicate error N times
54-
// May be handy do demultiplex a single original error to a number of callers/requests
53+
// ReplicateError is a utility function to duplicate error N times.
54+
// May be handy do demultiplex a single original error to a number of callers/requests.
5555
func ReplicateError(err error, count int) []error {
5656
result := make([]error, count)
5757
for i := range result {

wrap.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package errorx
22

33
var (
4-
// most errors from this namespace are made private in order to disallow and direct type checks in the user code
4+
// Most errors from this namespace are made private in order to disallow and direct type checks in the user code
55
syntheticErrors = NewNamespace("synthetic")
66

77
// Private error type for non-errors errors, used as a not-nil substitute that cannot be type-checked directly
@@ -14,10 +14,10 @@ var (
1414
stackTraceWrapper = syntheticErrors.NewType("stacktrace").ApplyModifiers(TypeModifierTransparent)
1515
)
1616

17-
// Pass some text info along with a message, leaving its semantics totally intact
18-
// An perceived type, traits and properties if the resulting error are those of the original
19-
// Without args, leaves the provided message intact, so a message may be generated or provided externally
20-
// With args, a formatting is performed, and it is therefore expected a format string to be constant
17+
// Decorate allows to pass some text info along with a message, leaving its semantics totally intact.
18+
// An perceived type, traits and properties if the resulting error are those of the original.
19+
// Without args, leaves the provided message intact, so a message may be generated or provided externally.
20+
// With args, a formatting is performed, and it is therefore expected a format string to be constant.
2121
func Decorate(err error, message string, args ...interface{}) *Error {
2222
return NewErrorBuilder(transparentWrapper).
2323
WithConditionallyFormattedMessage(message, args...).
@@ -26,9 +26,10 @@ func Decorate(err error, message string, args ...interface{}) *Error {
2626
Create()
2727
}
2828

29-
// Has all the properties of the Decorate() method and additionally extends the stack trace of the original message
30-
// Designed to be used when a original error is passed from another goroutine rather than from a direct method call
31-
// If, however, is it is call in the same goroutine, formatter makes some moderated effort to remove duplication
29+
// EnhanceStackTrace has all the properties of the Decorate() method
30+
// and additionally extends the stack trace of the original message.
31+
// Designed to be used when a original error is passed from another goroutine rather than from a direct method call.
32+
// If, however, is it is call in the same goroutine, formatter makes some moderated effort to remove duplication.
3233
func EnhanceStackTrace(err error, message string, args ...interface{}) *Error {
3334
return NewErrorBuilder(transparentWrapper).
3435
WithConditionallyFormattedMessage(message, args...).
@@ -38,9 +39,9 @@ func EnhanceStackTrace(err error, message string, args ...interface{}) *Error {
3839
Create()
3940
}
4041

41-
// Utility to ensure the stack trace is captured in provided error
42-
// If this is already true, it is returned unmodified
43-
// Otherwise, it is decorated with stack trace
42+
// EnsureStackTrace is a utility to ensure the stack trace is captured in provided error.
43+
// If this is already true, it is returned unmodified.
44+
// Otherwise, it is decorated with stack trace.
4445
func EnsureStackTrace(err error) *Error {
4546
if typedErr := Cast(err); typedErr != nil && typedErr.stackTrace != nil {
4647
return typedErr
@@ -54,10 +55,10 @@ func EnsureStackTrace(err error) *Error {
5455
Create()
5556
}
5657

57-
// Transparent wrap of multiple errors with additional message
58-
// If there are no errors, or all errors are nil, returns nil
59-
// If all errors are of the same type (for example, if there is only one), wraps them transparently
60-
// Otherwise, an opaque wrap is performed, that is, IsOfType checks will fail on underlying error types
58+
// DecorateMany performs a transparent wrap of multiple errors with additional message.
59+
// If there are no errors, or all errors are nil, returns nil.
60+
// If all errors are of the same type (for example, if there is only one), wraps them transparently.
61+
// Otherwise, an opaque wrap is performed, that is, IsOfType checks will fail on underlying error types.
6162
func DecorateMany(message string, errs ...error) error {
6263
errs = ignoreEmpty(errs)
6364
if len(errs) == 0 {
@@ -71,9 +72,9 @@ func DecorateMany(message string, errs ...error) error {
7172
}
7273
}
7374

74-
// Utility to wrap multiple errors
75-
// If there are no errors, or all errors are nil, returns nil
76-
// Otherwise, the fist error is treated as an original cause, others are added as underlying
75+
// WrapMany is a utility to wrap multiple errors.
76+
// If there are no errors, or all errors are nil, returns nil.
77+
// Otherwise, the fist error is treated as an original cause, others are added as underlying.
7778
func WrapMany(errorType *Type, message string, errs ...error) error {
7879
errs = ignoreEmpty(errs)
7980
if len(errs) == 0 {

0 commit comments

Comments
 (0)