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

Commitd673079

Browse files
authored
Add err wrapping to dialer (#402)
1 parent961f7dd commitd673079

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

‎wsnet/dial.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
104104
returnnil,fmt.Errorf("create peer connection: %w",err)
105105
}
106106
log.Debug(ctx,"created peer connection")
107+
deferfunc() {
108+
iferr!=nil {
109+
// Wrap our error with some extra details.
110+
err=errWrap{
111+
err:err,
112+
iceServers:rtc.GetConfiguration().ICEServers,
113+
rtc:rtc.ConnectionState(),
114+
}
115+
}
116+
}()
117+
107118
rtc.OnConnectionStateChange(func(pcs webrtc.PeerConnectionState) {
108119
log.Debug(ctx,"connection state change",slog.F("state",pcs.String()))
109120
})
@@ -159,7 +170,9 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
159170
connClosers: []io.Closer{ctrl},
160171
}
161172

162-
returndialer,dialer.negotiate(ctx)
173+
// This is on a separate line so the defer above catches it.
174+
err=dialer.negotiate(ctx)
175+
returndialer,err
163176
}
164177

165178
// Dialer enables arbitrary dialing to any network and address

‎wsnet/error.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package wsnet
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/pion/webrtc/v3"
8+
)
9+
10+
// errWrap wraps the error with some extra details about the state of the
11+
// connection.
12+
typeerrWrapstruct {
13+
errerror
14+
15+
iceServers []webrtc.ICEServer
16+
rtc webrtc.PeerConnectionState
17+
}
18+
19+
var_error=errWrap{}
20+
var_interface{Unwrap()error }=errWrap{}
21+
22+
// Error implements error.
23+
func (eerrWrap)Error()string {
24+
returnfmt.Sprintf("%v (ice: [%v], rtc: %v)",e.err.Error(),e.ice(),e.rtc.String())
25+
}
26+
27+
func (eerrWrap)ice()string {
28+
msgs:= []string{}
29+
for_,s:=rangee.iceServers {
30+
msgs=append(msgs,strings.Join(s.URLs,", "))
31+
}
32+
33+
returnstrings.Join(msgs,", ")
34+
}
35+
36+
// Unwrap implements Unwrapper.
37+
func (eerrWrap)Unwrap()error {
38+
returne.err
39+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp