@@ -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.
1111type Type struct {
1212 namespace Namespace
1313 parent * Type
@@ -19,62 +19,62 @@ type Type struct {
1919
2020var _ encoding.TextMarshaler = (* Type )(nil )
2121
22- // Defines a new distinct type within a namespace
22+ // NewType defines a new distinct type within a namespace.
2323func 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.
2828func (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.
3333func (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.
4141func (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.
4949func (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.
5959func (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.
7070func (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.
7878func (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.
9494func 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.
100100func (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.
105105func (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.
110110func (t * Type ) RootNamespace () Namespace {
111111 return t .namespace
112112}
0 commit comments