Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions neo4j/internal/errorutil/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (crt *ConnectionReadTimeout) Error() string {
crt.Err)
}

func (crt *ConnectionReadTimeout) Unwrap() error {
return crt.Err
}

type ConnectionWriteTimeout struct {
UserContext context.Context
Err error
Expand All @@ -58,6 +62,10 @@ func (cwt *ConnectionWriteTimeout) Error() string {
return fmt.Sprintf("Timeout while writing to connection [user-provided context deadline: %s]: %s", userDeadline, cwt.Err)
}

func (crt *ConnectionWriteTimeout) Unwrap() error {
return crt.Err
}

type ConnectionReadCanceled struct {
Err error
}
Expand All @@ -66,6 +74,10 @@ func (crc *ConnectionReadCanceled) Error() string {
return fmt.Sprintf("Reading from connection has been canceled: %s", crc.Err)
}

func (crt *ConnectionReadCanceled) Unwrap() error {
return crt.Err
}

type ConnectionWriteCanceled struct {
Err error
}
Expand All @@ -74,6 +86,10 @@ func (cwc *ConnectionWriteCanceled) Error() string {
return fmt.Sprintf("Writing to connection has been canceled: %s", cwc.Err)
}

func (crt *ConnectionWriteCanceled) Unwrap() error {
return crt.Err
}

type timeout interface {
Timeout() bool
}
Expand Down
36 changes: 35 additions & 1 deletion neo4j/internal/errorutil/bolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package errorutil_test

import (
"context"
"errors"
"testing"

"github.com/neo4j/neo4j-go-driver/v5/neo4j/db"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/errorutil"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/internal/testutil"
"testing"
)

func TestIsFatalDuringDiscovery(outer *testing.T) {
Expand Down Expand Up @@ -138,3 +140,35 @@ func TestIsFatalDuringDiscovery(outer *testing.T) {
})
}
}

func TestErrorSupportsUnwrap(outer *testing.T) {
type testCase struct {
description string
err error
}

inner := errors.New("the inner error")

testCases := []testCase{
{
description: "ConnectionReadTimeout support Unwrap",
err: &errorutil.ConnectionReadTimeout{Err: inner},
}, {
description: "ConnectionWriteTimeout support Unwrap",
err: &errorutil.ConnectionWriteTimeout{Err: inner},
}, {
description: "ConnectionReadCanceled support Unwrap",
err: &errorutil.ConnectionReadCanceled{Err: inner},
}, {
description: "ConnectionWriteCanceled support Unwrap",
err: &errorutil.ConnectionWriteCanceled{Err: inner},
},
}

for _, testCase := range testCases {
outer.Run(testCase.description, func(t *testing.T) {

testutil.AssertBoolEqual(t, errors.Is(testCase.err, inner), true)
})
}
}