Skip to content

Commit a86349f

Browse files
committed
fix dogoc comments
1 parent 5213437 commit a86349f

6 files changed

Lines changed: 62 additions & 61 deletions

File tree

panic.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package errorx
22

33
import "fmt"
44

5-
// When calling panic as a reaction to error, prefer this function over vanilla panic()
5+
// Panic is an alternative to the built-in panic call.
6+
// When calling panic as a reaction to error, prefer this function over vanilla panic().
67
// If err happens to be an errorx error, it may hold the original stack trace of the issue.
7-
// With panic(err), this information may be lost if panic is handled by the default handler
8+
// With panic(err), this information may be lost if panic is handled by the default handler.
89
// With errorx.Panic(err), all data is preserved regardless of the handle mechanism.
9-
// It can be recovered either from default panic message, recover() result or ErrorFromPanic() function
10+
// It can be recovered either from default panic message, recover() result or ErrorFromPanic() function.
1011
//
1112
// Even if err stack trace is exactly the same as default panic trace, this can be tolerated,
1213
// as panics must not be a way to report conventional errors and are therefore rare.
13-
// With this in mind, it is better to err on the side of completeness rather than brevity
14+
// With this in mind, it is better to err on the side of completeness rather than brevity.
1415
//
1516
// This function never returns, but the signature may be convenient, i.e.:
1617
// * return nil, errorx.Panic(err)
@@ -19,15 +20,15 @@ func Panic(err error) error {
1920
panic(newPanicErrorWrapper(err))
2021
}
2122

22-
// Recover the original error from panic, best employed along with Panic() function from the same package.
23+
// ErrorFromPanic recovers the original error from panic, best employed along with Panic() function from the same package.
2324
// The original error, if present, typically holds more relevant data
24-
// than a combination of panic message and the stack trace which can be collected after recover()
25+
// than a combination of panic message and the stack trace which can be collected after recover().
2526
//
2627
// More importantly, it allows for greater composability,
27-
// if ever there is a need to recover from panic and pass the error information forwards in its proper form
28+
// if ever there is a need to recover from panic and pass the error information forwards in its proper form.
2829
//
2930
// Note that panic is not a proper means to report errors,
30-
// so this mechanism should never be used where a error based control flow is at all possible
31+
// so this mechanism should never be used where a error based control flow is at all possible.
3132
func ErrorFromPanic(recoverResult interface{}) (error, bool) {
3233
err, ok := recoverResult.(error)
3334
if !ok {

property.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1010
type 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.
1717
func 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.
2222
func 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.
2727
func 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.
3232
func 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.
3737
func 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.
4747
func 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.
5252
func 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.
5858
func ExtractProperty(err error, key Property) (interface{}, bool) {
5959
typedErr := Cast(err)
6060
if typedErr == nil {

registry.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package errorx
22

33
import "sync"
44

5-
// An interface to receive callbacks on the registered error namespaces and types
6-
// This may be used to create a user-defined registry, for example, to check if all type names are unique
7-
// ISSUE: if .ApplyModifiers is called for a type/namespace, callback still receives a value without those modifiers
5+
// TypeSubscriber is an interface to receive callbacks on the registered error namespaces and types.
6+
// This may be used to create a user-defined registry, for example, to check if all type names are unique.
7+
// ISSUE: if .ApplyModifiers is called for a type/namespace, callback still receives a value without those modifiers.
88
type TypeSubscriber interface {
99
// Method is called exactly once for each namespace
1010
OnNamespaceCreated(namespace Namespace)
1111
// Method is called exactly once for each type
1212
OnTypeCreated(t *Type)
1313
}
1414

15-
// Add a new TypeSubscriber
16-
// A subscriber is guaranteed to receive callbacks for all namespaces and types
17-
// If a type is already registered at the moment of subscription, a callback for this type is called immediately
15+
// RegisterTypeSubscriber adds a new TypeSubscriber.
16+
// A subscriber is guaranteed to receive callbacks for all namespaces and types.
17+
// If a type is already registered at the moment of subscription, a callback for this type is called immediately.
1818
func RegisterTypeSubscriber(s TypeSubscriber) {
1919
globalRegistry.registerTypeSubscriber(s)
2020
}

stacktrace.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
// A used defined transformer for file path in stack trace output
1313
type StackTraceFilePathTransformer func(string) string
1414

15-
// Provide a transformer to be used in formatting of all the errors
16-
// It is OK to leave it alone, stack trace will retain its exact original information
17-
// This feature may be beneficial, however, if a shortening of file path will make it more convenient to use
18-
// One of such examples is to transform a project-related path from absolute to relative and thus more IDE-friendly
15+
// InitializeStackTraceTransformer provides a transformer to be used in formatting of all the errors.
16+
// It is OK to leave it alone, stack trace will retain its exact original information.
17+
// This feature may be beneficial, however, if a shortening of file path will make it more convenient to use.
18+
// One of such examples is to transform a project-related path from absolute to relative and thus more IDE-friendly.
1919
//
20-
// NB: error is returned if a transformer was already registered
21-
// Transformer is changed nonetheless, the old one is returned along with an error
20+
// NB: error is returned if a transformer was already registered.
21+
// Transformer is changed nonetheless, the old one is returned along with an error.
2222
// User is at liberty to either ignore it, panic, reinstate the old transformer etc.
2323
func InitializeStackTraceTransformer(transformer StackTraceFilePathTransformer) (StackTraceFilePathTransformer, error) {
2424
stackTraceTransformer.mu.Lock()

switch.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ var (
1212
caseNoTrait = RegisterTrait("synthetic.no.trait")
1313
)
1414

15-
// Used to perform a switch around the type of an error
16-
// For nil errors, returns nil
17-
// For error types not in the 'types' list, including non-errorx errors, NotRecognisedType() is returned
18-
// It is safe to treat NotRecognisedType() as 'any other type of not-nil error' case
19-
// The effect is equivalent to a series of IsOfType() checks
20-
// NB: if more than one provided types matches with error, the first match in the providers list is recognised
15+
// TypeSwitch is used to perform a switch around the type of an error.
16+
// For nil errors, returns nil.
17+
// For error types not in the 'types' list, including non-errorx errors, NotRecognisedType() is returned.
18+
// It is safe to treat NotRecognisedType() as 'any other type of not-nil error' case.
19+
// The effect is equivalent to a series of IsOfType() checks.
20+
// NB: if more than one provided types matches with error, the first match in the providers list is recognised.
2121
func TypeSwitch(err error, types ...*Type) *Type {
2222
typed := Cast(err)
2323

@@ -37,12 +37,12 @@ func TypeSwitch(err error, types ...*Type) *Type {
3737
}
3838
}
3939

40-
// Used to perform a switch around the trait of an error
41-
// For nil errors, returns CaseNoError()
42-
// For error types that lack any of the provided traits, including non-errorx errors, CaseNoTrait() is returned
43-
// It is safe to treat CaseNoTrait() as 'any other kind of not-nil error' case
44-
// The effect is equivalent to a series of HasTrait() checks
45-
// NB: if more than one provided types matches with error, the first match in the providers list is recognised
40+
// TraitSwitch is used to perform a switch around the trait of an error.
41+
// For nil errors, returns CaseNoError().
42+
// For error types that lack any of the provided traits, including non-errorx errors, CaseNoTrait() is returned.
43+
// It is safe to treat CaseNoTrait() as 'any other kind of not-nil error' case.
44+
// The effect is equivalent to a series of HasTrait() checks.
45+
// NB: if more than one provided types matches with error, the first match in the providers list is recognised.
4646
func TraitSwitch(err error, traits ...Trait) Trait {
4747
typed := Cast(err)
4848

trait.go

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

3-
// Trait is a static characteristic of an error type
4-
// All errors of a specific type possess exactly the same traits
5-
// Traits are both defined along with an error and inherited from a supertype and a namespace
3+
// Trait is a static characteristic of an error type.
4+
// All errors of a specific type possess exactly the same traits.
5+
// Traits are both defined along with an error and inherited from a supertype and a namespace.
66
type Trait struct {
77
id int64
88
label string
99
}
1010

11-
// Declare a new distinct traits
12-
// Traits are matched exactly, distinct traits are considered separate event if they have the same label
11+
// RegisterTrait declares a new distinct traits.
12+
// Traits are matched exactly, distinct traits are considered separate event if they have the same label.
1313
func RegisterTrait(label string) Trait {
1414
return newTrait(label)
1515
}
1616

17-
// Check if an error possesses the expected trait
18-
// Traits are always a property of a type rather than of an instance, so trait check is an alternative to a type check
19-
// This alternative is preferable, though, as it is less brittle and generally creates less of a dependency
17+
// HasTrait checks if an error possesses the expected trait.
18+
// Traits are always a property of a type rather than of an instance, so trait check is an alternative to a type check.
19+
// This alternative is preferable, though, as it is less brittle and generally creates less of a dependency.
2020
func HasTrait(err error, key Trait) bool {
2121
typedErr := Cast(err)
2222
if typedErr == nil {
@@ -26,34 +26,34 @@ func HasTrait(err error, key Trait) bool {
2626
return typedErr.HasTrait(key)
2727
}
2828

29-
// A trait that signifies that an error is temporary in nature
29+
// A trait that signifies that an error is temporary in nature.
3030
func Temporary() Trait { return traitTemporary }
3131

32-
// A trait that signifies that an error is some sort iof timeout
32+
// A trait that signifies that an error is some sort iof timeout.
3333
func Timeout() Trait { return traitTimeout }
3434

35-
// A trait that marks such an error where the requested object is not found
35+
// A trait that marks such an error where the requested object is not found.
3636
func NotFound() Trait { return traitNotFound }
3737

38-
// A trait that marks such an error where an update is failed as a duplicate
38+
// A trait that marks such an error where an update is failed as a duplicate.
3939
func Duplicate() Trait { return traitDuplicate }
4040

41-
// Check for Temporary trait
41+
// IsTemporary checks for Temporary trait.
4242
func IsTemporary(err error) bool {
4343
return HasTrait(err, Temporary())
4444
}
4545

46-
// Check for Timeout trait
46+
// IsTimeout checks for Timeout trait.
4747
func IsTimeout(err error) bool {
4848
return HasTrait(err, Timeout())
4949
}
5050

51-
// Check for NotFound trait
51+
// IsNotFound checks for NotFound trait.
5252
func IsNotFound(err error) bool {
5353
return HasTrait(err, NotFound())
5454
}
5555

56-
// Check for Duplicate trait
56+
// IsDuplicate checks for Duplicate trait.
5757
func IsDuplicate(err error) bool {
5858
return HasTrait(err, Duplicate())
5959
}

0 commit comments

Comments
 (0)