Fix

"error is not nil but has a nil value" (Nil Interface Gotcha)

Fix the Go nil interface error by checking if the underlying value is nil before calling methods on the error.

The "error is not nil but has a nil value" error occurs because a Go interface variable holds a non-nil type (like an error) but its underlying value is nil, causing err != nil to be true while err.Error() panics. You must check both the interface and the underlying value to handle this correctly.

if err != nil {
    if err.Error() == "" {
        // Handle the nil-value case
        return
    }
    // Handle the actual error
    return err
}

Alternatively, if you control the function returning the error, ensure it returns nil instead of (*MyError)(nil). If you cannot change the source, use errors.Is or errors.As which handle this case safely, or explicitly check the concrete type if known.