-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
Go version
go version 1.25.5
Output of go env in your module/workspace:
AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/twiesing/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/twiesing/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/lx/0flh25sd5xv0mnjwvv6m7xd80000gn/T/go-build2001449953=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/twiesing/tmp/example/go.mod'
GOMODCACHE='/Users/twiesing/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/twiesing/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.25.5/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/twiesing/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.25.5/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.5'
GOWORK=''
PKG_CONFIG='pkg-config'What did you do?
The function errors.Join states that it "returns an error that wraps the given errors. "
The definition of "wraps" does not include an error wrapping itself:
// If e.Unwrap() returns a non-nil error w or a slice containing w,
// then we say that e wraps w.
However, in go1.25 in specific situations errors.Join seems to return a passed error unchanged.
As noted on golang-nuts, as of https://go.dev/cl/635115 if passed a single non-nil error that implements interface { Unwrap() []error} it returns that error unchanged.
The following program demonstrates the change in behavior between 1.24 and 1.25:
package main
import (
"errors"
"fmt"
)
func main() {
var x CustomError
fmt.Println(errors.Join(x) == x)
}
type CustomError struct{}
func (CustomError) Error() string {
return ""
}
func (CustomError) Unwrap() []error {
return []error{}
}See also https://groups.google.com/g/golang-nuts/c/N0D1g5Ec_ZU.
What did you see happen?
On go 1.25 the program prints true: https://go.dev/play/p/Ihkm6tL9HP-
What did you expect to see?
The same as in previous versions.
On go1.24 the same program prints false: https://go.dev/play/p/Ihkm6tL9HP-?v=goprev