Skip to content

Commit 389ddbb

Browse files
committed
♻️ refactor: add new function AppendErrors #2
1 parent ff12394 commit 389ddbb

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

replify.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,38 @@ func (w *wrapper) AppendErrorf(err error, format string, args ...any) *wrapper {
29832983
return w
29842984
}
29852985

2986+
// AppendErrors appends multiple errors to the `wrapper` instance.
2987+
//
2988+
// This function iterates through the provided errors slice, skips nil entries,
2989+
// and folds each error into the wrapper's internal error chain.
2990+
//
2991+
// Rules:
2992+
// - If `w.errors` is nil, it will be set to the first non-nil error.
2993+
// - For subsequent errors, it wraps the existing chain using AppendErrorAck
2994+
// with the error's message.
2995+
//
2996+
// Parameters:
2997+
// - errs: A slice of errors to be appended.
2998+
//
2999+
// Returns:
3000+
// - A pointer to the modified `wrapper` instance to support method chaining.
3001+
func (w *wrapper) AppendErrors(errs []error) *wrapper {
3002+
if !w.Available() || len(errs) == 0 {
3003+
return w
3004+
}
3005+
for _, err := range errs {
3006+
if err == nil {
3007+
continue
3008+
}
3009+
if w.errors == nil {
3010+
w.errors = err
3011+
continue
3012+
}
3013+
w.errors = AppendErrorAck(w.errors, err.Error())
3014+
}
3015+
return w
3016+
}
3017+
29863018
// BindCause sets the error for the `wrapper` instance using its current message.
29873019
//
29883020
// This function creates an error object from the `message` field of the `wrapper`,

0 commit comments

Comments
 (0)