diff --git a/error.go b/error.go index 44aecef25..c9b736855 100644 --- a/error.go +++ b/error.go @@ -23,7 +23,6 @@ import ( "net" "os" "reflect" - "syscall" "time" "go.elastic.co/apm/v2/model" @@ -596,13 +595,6 @@ func init() { details.SetAttr("syscall", syscallErr.Syscall) details.Cause = append(details.Cause, syscallErr.Err) })) - RegisterTypeErrorDetailer(reflect.TypeOf(syscall.Errno(0)), ErrorDetailerFunc(func(err error, details *ErrorDetails) { - errno := err.(syscall.Errno) - details.Code.String = errnoName(errno) - if details.Code.String == "" { - details.Code.Number = float64(errno) - } - })) } func errTemporary(err error) bool { diff --git a/error_go120_test.go b/error_syscall.go similarity index 55% rename from error_go120_test.go rename to error_syscall.go index 623bbe373..0d286bcb6 100644 --- a/error_go120_test.go +++ b/error_syscall.go @@ -15,30 +15,21 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.20 -// +build go1.20 +//go:build unix || windows -package apm_test +package apm // import "go.elastic.co/apm/v2" import ( - "context" - "errors" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "go.elastic.co/apm/v2" - "go.elastic.co/apm/v2/apmtest" + "reflect" + "syscall" ) -func TestErrorCauseUnwrapJoined(t *testing.T) { - err := errors.Join(errors.New("cause1"), errors.New("cause2")) - _, _, errors := apmtest.WithTransaction(func(ctx context.Context) { - apm.CaptureError(ctx, err).Send() - }) - require.Len(t, errors, 1) - require.Len(t, errors[0].Exception.Cause, 2) - assert.Equal(t, "cause1", errors[0].Exception.Cause[0].Message) - assert.Equal(t, "cause2", errors[0].Exception.Cause[1].Message) +func init() { + RegisterTypeErrorDetailer(reflect.TypeOf(syscall.Errno(0)), ErrorDetailerFunc(func(err error, details *ErrorDetails) { + errno := err.(syscall.Errno) + details.Code.String = errnoName(errno) + if details.Code.String == "" { + details.Code.Number = float64(errno) + } + })) } diff --git a/error_test.go b/error_test.go index 8ca9c32b0..6d105f995 100644 --- a/error_test.go +++ b/error_test.go @@ -19,6 +19,7 @@ package apm_test import ( "context" + goerrors "errors" "fmt" "net" "os" @@ -52,6 +53,17 @@ func TestErrorID(t *testing.T) { assert.Equal(t, model.TraceID(errorID), errors[0].ID) } +func TestErrorCauseUnwrapJoined(t *testing.T) { + err := goerrors.Join(errors.New("cause1"), errors.New("cause2")) + _, _, errors := apmtest.WithTransaction(func(ctx context.Context) { + apm.CaptureError(ctx, err).Send() + }) + require.Len(t, errors, 1) + require.Len(t, errors[0].Exception.Cause, 2) + assert.Equal(t, "cause1", errors[0].Exception.Cause[0].Message) + assert.Equal(t, "cause2", errors[0].Exception.Cause[1].Message) +} + func TestErrorsStackTrace(t *testing.T) { modelError := sendError(t, &errorsStackTracer{ "zing", newErrorsStackTrace(0, 2), diff --git a/error_unix.go b/error_unix.go index 2666acd97..c2a8a4aec 100644 --- a/error_unix.go +++ b/error_unix.go @@ -15,8 +15,7 @@ // specific language governing permissions and limitations // under the License. -//go:build !windows -// +build !windows +//go:build unix package apm // import "go.elastic.co/apm/v2" diff --git a/error_windows.go b/error_windows.go index e0e1fdcf9..7655179e1 100644 --- a/error_windows.go +++ b/error_windows.go @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +//go:build windows + package apm // import "go.elastic.co/apm/v2" import (