|
61 | 61 | ErrInvalidArgumentType = errors.New("invalid argument type") |
62 | 62 | ErrOddKeyValueCount = errors.New("odd number of key-value arguments") |
63 | 63 | ErrCrossPackageError = errors.New("error from different doterr package") |
64 | | - ErrFailedTypeAssertion = errors.New("failed type assertion") |
65 | 64 | ) |
66 | 65 |
|
67 | 66 | // NewErr builds a standalone structured entry (no primary cause inside). |
|
76 | 75 | // remaining args must form valid pairs, except for an optional final error. |
77 | 76 | // Returns nil if no meaningful parts are provided after validation. |
78 | 77 | // Returns a validation error joined with the partial entry if validation fails. |
| 78 | +// |
| 79 | +//goland:noinspection DuplicatedCode |
79 | 80 | func NewErr(parts ...any) error { |
80 | 81 | // Separate optional trailing cause from the parts |
| 82 | + //goland:noinspection DuplicatedCode |
81 | 83 | coreParts, cause := extractTrailingCause(parts) |
82 | 84 |
|
83 | 85 | if validationErr := validateNewParts(coreParts); validationErr != nil { |
@@ -132,6 +134,8 @@ func NewErr(parts ...any) error { |
132 | 134 | // Note: For inter-function composition, prefer New() with trailing cause: |
133 | 135 | // |
134 | 136 | // return doterr.New(ErrRepo, "key", val, cause) // cause last |
| 137 | +// |
| 138 | +//goland:noinspection DuplicatedCode |
135 | 139 | func WithErr(parts ...any) error { |
136 | 140 | if len(parts) == 0 { |
137 | 141 | return nil |
@@ -199,6 +203,8 @@ func CombineErrs(errs []error) error { |
199 | 203 | // left-to-right and returns metadata from the first doterr entry found. |
200 | 204 | // Otherwise returns nil. |
201 | 205 | // The returned slice preserves insertion order and is a copy. |
| 206 | +// |
| 207 | +//goland:noinspection DuplicatedCode |
202 | 208 | func ErrMeta(err error) []KV { |
203 | 209 | var ok bool |
204 | 210 | var e, ce entry |
@@ -283,6 +289,8 @@ func ErrValue[T any](err error, key string) (T, bool) { |
283 | 289 | // |
284 | 290 | // Note: These errors may be sentinel errors (e.g., ErrRepo), custom error types |
285 | 291 | // (e.g., *rfc9457.Error), or any other error type stored in the entry. |
| 292 | +// |
| 293 | +//goland:noinspection DuplicatedCode |
286 | 294 | func Errors(err error) []error { |
287 | 295 | // Case (a): err is an entry → return its errors |
288 | 296 | //goland:noinspection GoTypeAssertionOnErrors |
@@ -361,6 +369,9 @@ func newEntry(errors []error, kvs []kv) *entry { |
361 | 369 | } |
362 | 370 | } |
363 | 371 |
|
| 372 | +// Error implements the std lib error interface and returns the strings value |
| 373 | +// |
| 374 | +//goland:noinspection DuplicatedCode |
364 | 375 | func (e entry) Error() string { |
365 | 376 | if len(e.errors) == 0 && len(e.kvs) == 0 { |
366 | 377 | return "doterr{}" |
@@ -396,6 +407,7 @@ func (e entry) Unwrap() []error { |
396 | 407 |
|
397 | 408 | func (e entry) empty() bool { return len(e.errors) == 0 && len(e.kvs) == 0 } |
398 | 409 |
|
| 410 | +//goland:noinspection DuplicatedCode |
399 | 411 | func appendEntry(e *entry, parts ...any) { |
400 | 412 | for i := 0; i < len(parts); { |
401 | 413 | switch v := parts[i].(type) { |
@@ -452,6 +464,8 @@ func (c combined) Unwrap() []error { |
452 | 464 | // - It's the last element, AND |
453 | 465 | // - It comes after at least one sentinel, AND |
454 | 466 | // - It's not part of an incomplete key-value pair (would leave odd count) |
| 467 | +// |
| 468 | +//goland:noinspection DuplicatedCode |
455 | 469 | func extractTrailingCause(parts []any) (_ []any, err error) { |
456 | 470 | var lastIdx, sentinelCount, nonSentinelCount int |
457 | 471 | var ok bool |
|
506 | 520 | // - Then zero or more KV or string key-value pairs |
507 | 521 | // - After the first string key, remaining args must form valid pairs (even count) |
508 | 522 | // - No non-string/non-error/non-KV values allowed |
| 523 | +// |
| 524 | +//goland:noinspection DuplicatedCode |
509 | 525 | func validateNewParts(parts []any) error { |
510 | 526 | if len(parts) == 0 { |
511 | 527 | // Build entry manually to avoid recursion |
@@ -660,6 +676,8 @@ func buildErr(baseErr error, middle []any) error { |
660 | 676 | // (b) one of the immediate children of a multi-unwrap (errors.Join) tree. |
661 | 677 | // |
662 | 678 | // It does NOT recurse deeper than one join level. |
| 679 | +// |
| 680 | +//goland:noinspection DuplicatedCode |
663 | 681 | func enrichRightmost(err error, parts ...any) (error, bool) { |
664 | 682 | // Case (a): err is an entry → merge directly. |
665 | 683 | //goland:noinspection GoTypeAssertionOnErrors |
|
0 commit comments