55 "strconv"
66)
77
8- // Utility to compose an error from type
9- // Typically, a direct usage is not required: either Type methods of helpers like Decorate is sufficient
10- // Only use builder if no neater alternative is available
8+ // ErrorBuilder is a utility to compose an error from type.
9+ // Typically, a direct usage is not required: either Type methods of helpers like Decorate is sufficient.
10+ // Only use builder if no neater alternative is available.
1111type ErrorBuilder struct {
1212 errorType * Type
1313 message string
@@ -17,7 +17,7 @@ type ErrorBuilder struct {
1717 isTransparent bool
1818}
1919
20- // Created error builder from an existing error type
20+ // NewErrorBuilder created error builder from an existing error type
2121func NewErrorBuilder (t * Type ) * ErrorBuilder {
2222 getMode := func () callStackBuildMode {
2323 if t .modifiers .CollectStackTrace () {
@@ -34,10 +34,10 @@ func NewErrorBuilder(t *Type) *ErrorBuilder {
3434 }
3535}
3636
37- // Provide an original cause for error
38- // For non-errorx errors, a stack trace is collected
39- // Otherwise, it is inherited by default, as error wrapping is typically performed 'en passe'
40- // Note that even if an original error explicitly omitted the stack trace, it could be added on wrap
37+ // WithCause provides an original cause for error.
38+ // For non-errorx errors, a stack trace is collected.
39+ // Otherwise, it is inherited by default, as error wrapping is typically performed 'en passe'.
40+ // Note that even if an original error explicitly omitted the stack trace, it could be added on wrap.
4141func (eb * ErrorBuilder ) WithCause (err error ) * ErrorBuilder {
4242 eb .cause = err
4343 if Cast (err ) != nil {
@@ -47,9 +47,10 @@ func (eb *ErrorBuilder) WithCause(err error) *ErrorBuilder {
4747 return eb
4848}
4949
50- // Transparent wrap hides the current error type from the type checks and exposes the error type of the cause instead
51- // The same holds true for traits, and the dynamic properties are visible from both cause and transparent wrapper
52- // Note that if the cause error is non-errorx, transparency will still hold, type check against wrapper will still fail
50+ // Transparent makes a wrap transparent rather than opaque (default).
51+ // Transparent wrap hides the current error type from the type checks and exposes the error type of the cause instead.
52+ // The same holds true for traits, and the dynamic properties are visible from both cause and transparent wrapper.
53+ // Note that if the cause error is non-errorx, transparency will still hold, type check against wrapper will still fail.
5354func (eb * ErrorBuilder ) Transparent () * ErrorBuilder {
5455 if eb .cause == nil {
5556 panic ("wrong builder usage: wrap modifier without non-nil cause" )
@@ -59,11 +60,11 @@ func (eb *ErrorBuilder) Transparent() *ErrorBuilder {
5960 return eb
6061}
6162
62- // Collect the current stack trace along with the original one, and use both in formatting
63- // If the original error does not hold a stack trace for whatever reason, it will be collected it this point
64- // This is typically a way to handle an error received from another goroutine - say, a worker pool
63+ // EnhanceStackTrace is a signal to collect the current stack trace along with the original one, and use both in formatting.
64+ // If the original error does not hold a stack trace for whatever reason, it will be collected it this point.
65+ // This is typically a way to handle an error received from another goroutine - say, a worker pool.
6566// When stack traces overlap, formatting makes a conservative attempt not to repeat itself,
66- // preserving the *original* stack trace in its entirety
67+ // preserving the *original* stack trace in its entirety.
6768func (eb * ErrorBuilder ) EnhanceStackTrace () * ErrorBuilder {
6869 if eb .cause == nil {
6970 panic ("wrong builder usage: wrap modifier without non-nil cause" )
@@ -78,16 +79,9 @@ func (eb *ErrorBuilder) EnhanceStackTrace() *ErrorBuilder {
7879 return eb
7980}
8081
81- // Adds multiple additional (hidden, suppressed) related errors to be used exclusively in error output
82- // Note that these errors make no other effect whatsoever: their traits, types, properties etc. are lost
83- func (eb * ErrorBuilder ) withUnderlyingErrors (errs ... error ) * ErrorBuilder {
84- eb .underlying = append (eb .underlying , errs ... )
85- return eb
86- }
87-
88- // Provides a message for an error in flexible format, to simplify its usages
89- // Without args, leaves the original message intact, so a message may be generated or provided externally
90- // With args, a formatting is performed, and it is therefore expected a format string to be constant
82+ // WithConditionallyFormattedMessage provides a message for an error in flexible format, to simplify its usages.
83+ // Without args, leaves the original message intact, so a message may be generated or provided externally.
84+ // With args, a formatting is performed, and it is therefore expected a format string to be constant.
9185func (eb * ErrorBuilder ) WithConditionallyFormattedMessage (message string , args ... interface {}) * ErrorBuilder {
9286 if len (args ) == 0 {
9387 eb .message = message
@@ -98,7 +92,7 @@ func (eb *ErrorBuilder) WithConditionallyFormattedMessage(message string, args .
9892 return eb
9993}
10094
101- // Returns an error with specified params
95+ // Create returns an error with specified params
10296func (eb * ErrorBuilder ) Create () * Error {
10397 return & Error {
10498 errorType : eb .errorType ,
0 commit comments