Skip to content

Commit 47debd3

Browse files
kzysaustinvazquez
authored andcommitted
Wrap vsock-related errors to explain the context
tryConnect() has multiple error cases which would be difficult to understand. This change adds some context on each of them. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent abc4a34 commit 47debd3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/vm/vsock.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func vsockConnectMsg(port uint32) string {
194194
func tryConnect(logger *logrus.Entry, udsPath string, port uint32) (net.Conn, error) {
195195
conn, err := net.DialTimeout("unix", udsPath, unixDialTimeout)
196196
if err != nil {
197-
return nil, err
197+
return nil, errors.Wrapf(err, "failed to dial %q within %s", udsPath, unixDialTimeout)
198198
}
199199

200200
defer func() {
@@ -207,14 +207,19 @@ func tryConnect(logger *logrus.Entry, udsPath string, port uint32) (net.Conn, er
207207
}
208208
}()
209209

210-
err = tryConnWrite(conn, vsockConnectMsg(port), vsockConnectMsgTimeout)
210+
msg := vsockConnectMsg(port)
211+
err = tryConnWrite(conn, msg, vsockConnectMsgTimeout)
211212
if err != nil {
212-
return nil, vsockConnectMsgError{cause: err}
213+
return nil, vsockConnectMsgError{
214+
cause: errors.Wrapf(err, `failed to write %q within %s`, msg, vsockConnectMsgTimeout),
215+
}
213216
}
214217

215218
line, err := tryConnReadUntil(conn, '\n', vsockAckMsgTimeout)
216219
if err != nil {
217-
return nil, vsockAckError{cause: err}
220+
return nil, vsockAckError{
221+
cause: errors.Wrapf(err, `failed to read "OK <port>" within %s`, vsockAckMsgTimeout),
222+
}
218223
}
219224

220225
// The line would be "OK <assigned_hostside_port>\n", but we don't use the hostside port here.

0 commit comments

Comments
 (0)