Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 799fbf2

Browse files
authored
Merge pull request #176 from grafana/improve/conn-execctx-logs
2 parents 4d18085 + e9107b3 commit 799fbf2

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

common/connection.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ func NewConnection(ctx context.Context, wsURL string, logger *Logger) (*Connecti
153153
// closeConnection cleanly closes the WebSocket connection.
154154
// Returns an error if sending the close control frame fails.
155155
func (c *Connection) closeConnection(code int) error {
156-
var err error
156+
c.logger.Debugf("Connection:closeConnection", "code:%d", code)
157157

158+
var err error
158159
c.shutdownOnce.Do(func() {
159160
defer func() {
160161
_ = c.conn.Close()
@@ -234,6 +235,7 @@ func (c *Connection) handleIOError(err error) {
234235
func (c *Connection) getSession(id target.SessionID) *Session {
235236
c.sessionsMu.RLock()
236237
defer c.sessionsMu.RUnlock()
238+
237239
return c.sessions[id]
238240
}
239241

common/execution_context.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,24 @@ func (e *ExecutionContext) evaluate(
198198
WithAwaitPromise(true).
199199
WithUserGesture(true)
200200
if remoteObject, exceptionDetails, err = action.Do(cdp.WithExecutor(apiCtx, e.session)); err != nil {
201-
return nil, fmt.Errorf("cannot evaluate expression (%s): %w", expressionWithSourceURL, exceptionDetails)
201+
return nil, fmt.Errorf("cannot call function on expression (%q) "+
202+
"in execution context (%d) in frame (%v): %w",
203+
expressionWithSourceURL, e.id, e.Frame().ID(), err)
202204
}
203205
if exceptionDetails != nil {
204-
return nil, fmt.Errorf("cannot evaluate expression (%s): %w", expressionWithSourceURL, exceptionDetails)
206+
return nil, fmt.Errorf("cannot call function on expression (%q) "+
207+
"in execution context (%d) in frame (%v): %w",
208+
expressionWithSourceURL, e.id, e.Frame().ID(), err)
205209
}
206210
if remoteObject == nil {
207211
return
208212
}
209213
if opts.returnByValue {
210214
res, err = valueFromRemoteObject(apiCtx, remoteObject)
211215
if err != nil {
212-
return nil, fmt.Errorf("cannot extract value from remote object (%s): %w", remoteObject.ObjectID, err)
216+
return nil, fmt.Errorf("cannot extract value from remote object (%s) "+
217+
"using (%s) in execution context (%d) in frame (%v): %w",
218+
remoteObject.ObjectID, expressionWithSourceURL, e.id, e.Frame().ID(), err)
213219
}
214220
} else if remoteObject.ObjectID != "" {
215221
// Note: we don't use the passed in apiCtx here as it could be tied to a timeout
@@ -220,7 +226,9 @@ func (e *ExecutionContext) evaluate(
220226
for _, arg := range args {
221227
result, err := convertArgument(apiCtx, e, arg)
222228
if err != nil {
223-
return nil, fmt.Errorf("cannot convert argument (%q): %w", arg, err)
229+
return nil, fmt.Errorf("cannot convert argument (%q) "+
230+
"in execution context (%d) in frame (%v): %w",
231+
arg, e.id, e.Frame().ID(), err)
224232
}
225233
arguments = append(arguments, result)
226234
}
@@ -237,18 +245,24 @@ func (e *ExecutionContext) evaluate(
237245
WithAwaitPromise(true).
238246
WithUserGesture(true)
239247
if remoteObject, exceptionDetails, err = action.Do(cdp.WithExecutor(apiCtx, e.session)); err != nil {
240-
return nil, fmt.Errorf("cannot call function on expression (%q) in execution context (%d): %w", expressionWithSourceURL, e.id, err)
248+
return nil, fmt.Errorf("cannot call function on expression (%q) "+
249+
"in execution context (%d) in frame (%v): %w",
250+
expressionWithSourceURL, e.id, e.Frame().ID(), err)
241251
}
242252
if exceptionDetails != nil {
243-
return nil, fmt.Errorf("cannot call function on expression (%q) in execution context (%d): %w", expressionWithSourceURL, e.id, err)
253+
return nil, fmt.Errorf("cannot call function on expression (%q) "+
254+
"in execution context (%d) in frame (%v): %w",
255+
expressionWithSourceURL, e.id, e.Frame().ID(), err)
244256
}
245257
if remoteObject == nil {
246258
return
247259
}
248260
if opts.returnByValue {
249261
res, err = valueFromRemoteObject(apiCtx, remoteObject)
250262
if err != nil {
251-
return nil, fmt.Errorf("cannot extract value from remote object (%s): %w", remoteObject.ObjectID, err)
263+
return nil, fmt.Errorf("cannot extract value from remote object (%s) "+
264+
"in execution context (%d) in frame (%v): %w",
265+
remoteObject.ObjectID, e.id, e.Frame().ID(), err)
252266
}
253267
} else if remoteObject.ObjectID != "" {
254268
// Note: we don't use the passed in apiCtx here as it could be tied to a timeout

0 commit comments

Comments
 (0)