mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2025-10-14 04:28:51 +02:00
17 lines
379 B
Go
17 lines
379 B
Go
package errs
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// Capture runs errFunc and assigns the error, if any, to *errPtr. Preserves the
|
|
// original error by wrapping with errors.Join if the errFunc err is non-nil.
|
|
func Capture(errPtr *error, errFunc func() error, msg string) {
|
|
err := errFunc()
|
|
if err == nil {
|
|
return
|
|
}
|
|
*errPtr = errors.Join(*errPtr, fmt.Errorf("%s: %w", msg, err))
|
|
}
|