Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Add err wrapping to dialer#402

Merged
deansheather merged 1 commit intomasterfromerr-wrap
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
15 changes: 14 additions & 1 deletionwsnet/dial.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -104,6 +104,17 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
return nil, fmt.Errorf("create peer connection: %w", err)
}
log.Debug(ctx, "created peer connection")
defer func() {
if err != nil {
// Wrap our error with some extra details.
err = errWrap{
err: err,
iceServers: rtc.GetConfiguration().ICEServers,
rtc: rtc.ConnectionState(),
}
}
}()

rtc.OnConnectionStateChange(func(pcs webrtc.PeerConnectionState) {
log.Debug(ctx, "connection state change", slog.F("state", pcs.String()))
})
Expand DownExpand Up@@ -159,7 +170,9 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
connClosers: []io.Closer{ctrl},
}

return dialer, dialer.negotiate(ctx)
// This is on a separate line so the defer above catches it.
err = dialer.negotiate(ctx)
return dialer, err
}

// Dialer enables arbitrary dialing to any network and address
Expand Down
39 changes: 39 additions & 0 deletionswsnet/error.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
package wsnet

import (
"fmt"
"strings"

"github.com/pion/webrtc/v3"
)

// errWrap wraps the error with some extra details about the state of the
// connection.
type errWrap struct {
err error

iceServers []webrtc.ICEServer
rtc webrtc.PeerConnectionState
}

var _ error = errWrap{}
var _ interface{ Unwrap() error } = errWrap{}

// Error implements error.
func (e errWrap) Error() string {
return fmt.Sprintf("%v (ice: [%v], rtc: %v)", e.err.Error(), e.ice(), e.rtc.String())
}

func (e errWrap) ice() string {
msgs := []string{}
for _, s := range e.iceServers {
msgs = append(msgs, strings.Join(s.URLs, ", "))
}

return strings.Join(msgs, ", ")
}

// Unwrap implements Unwrapper.
func (e errWrap) Unwrap() error {
return e.err
}

[8]ページ先頭

©2009-2025 Movatter.jp