@@ -4,36 +4,36 @@ import (
44 "context"
55)
66
7- // Key to a dynamic property of an error
8- // Property value belongs to an error instance only, never inherited from a type
9- // Property visibility is hindered by Wrap, preserved by Decorate
7+ // Property is a key to a dynamic property of an error.
8+ // Property value belongs to an error instance only, never inherited from a type.
9+ // Property visibility is hindered by Wrap, preserved by Decorate.
1010type Property struct {
1111 id int64
1212 label string
1313}
1414
15- // Register a new property key
16- // It is used both to add a dynamic property to an error instance, and to extract property value back from error
15+ // RegisterProperty registers a new property key.
16+ // It is used both to add a dynamic property to an error instance, and to extract property value back from error.
1717func RegisterProperty (label string ) Property {
1818 return newProperty (label )
1919}
2020
21- // Context property, value is expected to be of context.Context type
21+ // Context property, value is expected to be of context.Context type.
2222func PropertyContext () Property {
2323 return propertyContext
2424}
2525
26- // Payload property, value may contain user defined structure with arbitrary data passed along with an error
26+ // Payload property, value may contain user defined structure with arbitrary data passed along with an error.
2727func PropertyPayload () Property {
2828 return propertyPayload
2929}
3030
31- // A statically typed helper to add a context property to an error
31+ // WithContext is a statically typed helper to add a context property to an error.
3232func WithContext (err * Error , ctx context.Context ) * Error {
3333 return err .WithProperty (PropertyContext (), ctx )
3434}
3535
36- // A statically typed helper to extract a context property from an error
36+ // ExtractContext is a statically typed helper to extract a context property from an error.
3737func ExtractContext (err error ) (context.Context , bool ) {
3838 rawCtx , ok := ExtractProperty (err , PropertyContext ())
3939 if ! ok {
@@ -43,18 +43,18 @@ func ExtractContext(err error) (context.Context, bool) {
4343 return rawCtx .(context.Context ), true
4444}
4545
46- // A helper to add a payload property to an error
46+ // WithPayload is a helper to add a payload property to an error.
4747func WithPayload (err * Error , payload interface {}) * Error {
4848 return err .WithProperty (PropertyPayload (), payload )
4949}
5050
51- // Helper to add a payload property to an error
51+ // ExtractPayload is a helper to extract a payload property from an error.
5252func ExtractPayload (err error ) (interface {}, bool ) {
5353 return ExtractProperty (err , PropertyPayload ())
5454}
5555
56- // Attempt to extract a property value by a provided key
57- // A property may belong to this error, or be extracted from the original cause
56+ // ExtractProperty attempts to extract a property value by a provided key.
57+ // A property may belong to this error, or be extracted from the original cause.
5858func ExtractProperty (err error , key Property ) (interface {}, bool ) {
5959 typedErr := Cast (err )
6060 if typedErr == nil {
0 commit comments