From f869ff95a12756de97827b4afd93763f9661f144 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 8 Jun 2026 14:19:11 +0900 Subject: all: apply modernisers Signed-off-by: Ophestra --- container/errors.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'container/errors.go') diff --git a/container/errors.go b/container/errors.go index 5a67bb4c..053bdeb7 100644 --- a/container/errors.go +++ b/container/errors.go @@ -46,9 +46,8 @@ func messageFromError(err error) (m string, ok bool) { // While this is usable for pointer errors, such use should be avoided as nil // check is omitted. func messagePrefix[T error](prefix string, err error) (string, bool) { - var targetError T - if errors.As(err, &targetError) { - return prefix + targetError.Error(), true + if e, ok := errors.AsType[T](err); ok { + return prefix + e.Error(), true } return zeroString, false } @@ -58,9 +57,8 @@ func messagePrefixP[V any, T interface { *V error }](prefix string, err error) (string, bool) { - var targetError T - if errors.As(err, &targetError) && targetError != nil { - return prefix + targetError.Error(), true + if e, ok := errors.AsType[T](err); ok && e != nil { + return prefix + e.Error(), true } return zeroString, false } @@ -109,8 +107,8 @@ func optionalErrorUnwrap(err error) error { // errnoFallback returns the concrete errno from an error, or a [os.PathError] fallback. func errnoFallback(op, path string, err error) (syscall.Errno, *os.PathError) { - var errno syscall.Errno - if !errors.As(err, &errno) { + errno, ok := errors.AsType[syscall.Errno](err) + if !ok { return 0, &os.PathError{Op: op, Path: path, Err: err} } return errno, nil -- cgit v1.3.1