Skip to content

Commit

Permalink
add a Remote field to the StreamError
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 11, 2024
1 parent c5beefb commit df3ec9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const WebTransportBufferedStreamRejectedErrorCode quic.StreamErrorCode = 0x3994b
// StreamError is the error that is returned from stream operations (Read, Write) when the stream is canceled.
type StreamError struct {
ErrorCode StreamErrorCode
Remote bool
}

func (e *StreamError) Is(target error) bool {
Expand Down
5 changes: 4 additions & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ func maybeConvertStreamError(err error) error {
if cerr != nil {
return fmt.Errorf("stream reset, but failed to convert stream error %d: %w", streamErr.ErrorCode, cerr)
}
return &StreamError{ErrorCode: errorCode}
return &StreamError{
ErrorCode: errorCode,
Remote: streamErr.Remote,
}
}
return err
}
Expand Down
12 changes: 12 additions & 0 deletions webtransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func TestMultipleClients(t *testing.T) {

func TestStreamResetError(t *testing.T) {
const errorCode webtransport.StreamErrorCode = 127
strChan := make(chan webtransport.Stream, 1)
sess, closeServer := establishSession(t, func(sess *webtransport.Session) {
for {
str, err := sess.AcceptStream(context.Background())
Expand All @@ -368,10 +369,12 @@ func TestStreamResetError(t *testing.T) {
}
str.CancelRead(errorCode)
str.CancelWrite(errorCode)
strChan <- str
}
})
defer closeServer()

// client side
str, err := sess.OpenStream()
require.NoError(t, err)
_, err = str.Write([]byte("foobar"))
Expand All @@ -381,6 +384,15 @@ func TestStreamResetError(t *testing.T) {
var strErr *webtransport.StreamError
require.True(t, errors.As(err, &strErr))
require.Equal(t, strErr.ErrorCode, errorCode)
require.True(t, strErr.Remote)

// server side
str = <-strChan
_, err = str.Read([]byte{0})
require.Error(t, err)
require.True(t, errors.As(err, &strErr))
require.Equal(t, strErr.ErrorCode, errorCode)
require.False(t, strErr.Remote)
}

func TestShutdown(t *testing.T) {
Expand Down

0 comments on commit df3ec9c

Please sign in to comment.