Skip to content

Commit 0e8890c

Browse files
committed
test: Remove unused sentinel error, add IDE hints
- Remove unused `ErrFailedTypeAssertion` sentinel error from `doterr.go`. - Add `//goland:noinspection DuplicatedCode` directives to suppress IDE warnings for intentionally duplicated validation and error handling patterns in `NewErr()`, `WithErr()`, `ErrMeta()`, `Errors()`, `Error()`, `appendEntry()`, `extractTrailingCause()`, `validateNewParts()`, and `enrichRightmost()`. - Add documentation comment for `Error()` method to clarify it implements the standard library error interface.
1 parent ecb2104 commit 0e8890c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

doterr.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ var (
6161
ErrInvalidArgumentType = errors.New("invalid argument type")
6262
ErrOddKeyValueCount = errors.New("odd number of key-value arguments")
6363
ErrCrossPackageError = errors.New("error from different doterr package")
64-
ErrFailedTypeAssertion = errors.New("failed type assertion")
6564
)
6665

6766
// NewErr builds a standalone structured entry (no primary cause inside).
@@ -76,8 +75,11 @@ var (
7675
// remaining args must form valid pairs, except for an optional final error.
7776
// Returns nil if no meaningful parts are provided after validation.
7877
// Returns a validation error joined with the partial entry if validation fails.
78+
//
79+
//goland:noinspection DuplicatedCode
7980
func NewErr(parts ...any) error {
8081
// Separate optional trailing cause from the parts
82+
//goland:noinspection DuplicatedCode
8183
coreParts, cause := extractTrailingCause(parts)
8284

8385
if validationErr := validateNewParts(coreParts); validationErr != nil {
@@ -132,6 +134,8 @@ func NewErr(parts ...any) error {
132134
// Note: For inter-function composition, prefer New() with trailing cause:
133135
//
134136
// return doterr.New(ErrRepo, "key", val, cause) // cause last
137+
//
138+
//goland:noinspection DuplicatedCode
135139
func WithErr(parts ...any) error {
136140
if len(parts) == 0 {
137141
return nil
@@ -199,6 +203,8 @@ func CombineErrs(errs []error) error {
199203
// left-to-right and returns metadata from the first doterr entry found.
200204
// Otherwise returns nil.
201205
// The returned slice preserves insertion order and is a copy.
206+
//
207+
//goland:noinspection DuplicatedCode
202208
func ErrMeta(err error) []KV {
203209
var ok bool
204210
var e, ce entry
@@ -283,6 +289,8 @@ func ErrValue[T any](err error, key string) (T, bool) {
283289
//
284290
// Note: These errors may be sentinel errors (e.g., ErrRepo), custom error types
285291
// (e.g., *rfc9457.Error), or any other error type stored in the entry.
292+
//
293+
//goland:noinspection DuplicatedCode
286294
func Errors(err error) []error {
287295
// Case (a): err is an entry → return its errors
288296
//goland:noinspection GoTypeAssertionOnErrors
@@ -361,6 +369,9 @@ func newEntry(errors []error, kvs []kv) *entry {
361369
}
362370
}
363371

372+
// Error implements the std lib error interface and returns the strings value
373+
//
374+
//goland:noinspection DuplicatedCode
364375
func (e entry) Error() string {
365376
if len(e.errors) == 0 && len(e.kvs) == 0 {
366377
return "doterr{}"
@@ -396,6 +407,7 @@ func (e entry) Unwrap() []error {
396407

397408
func (e entry) empty() bool { return len(e.errors) == 0 && len(e.kvs) == 0 }
398409

410+
//goland:noinspection DuplicatedCode
399411
func appendEntry(e *entry, parts ...any) {
400412
for i := 0; i < len(parts); {
401413
switch v := parts[i].(type) {
@@ -452,6 +464,8 @@ func (c combined) Unwrap() []error {
452464
// - It's the last element, AND
453465
// - It comes after at least one sentinel, AND
454466
// - It's not part of an incomplete key-value pair (would leave odd count)
467+
//
468+
//goland:noinspection DuplicatedCode
455469
func extractTrailingCause(parts []any) (_ []any, err error) {
456470
var lastIdx, sentinelCount, nonSentinelCount int
457471
var ok bool
@@ -506,6 +520,8 @@ end:
506520
// - Then zero or more KV or string key-value pairs
507521
// - After the first string key, remaining args must form valid pairs (even count)
508522
// - No non-string/non-error/non-KV values allowed
523+
//
524+
//goland:noinspection DuplicatedCode
509525
func validateNewParts(parts []any) error {
510526
if len(parts) == 0 {
511527
// Build entry manually to avoid recursion
@@ -660,6 +676,8 @@ func buildErr(baseErr error, middle []any) error {
660676
// (b) one of the immediate children of a multi-unwrap (errors.Join) tree.
661677
//
662678
// It does NOT recurse deeper than one join level.
679+
//
680+
//goland:noinspection DuplicatedCode
663681
func enrichRightmost(err error, parts ...any) (error, bool) {
664682
// Case (a): err is an entry → merge directly.
665683
//goland:noinspection GoTypeAssertionOnErrors

0 commit comments

Comments
 (0)