Skip to content

Commit 32eca19

Browse files
committed
debugger: surface inspector failures in probe mode
This addresses a few TODOs left from the initial implementation around the error handling when the inspector session fails mid-probe - for example because a probe expression terminates the target, severs the inspector connection, or hangs the evaluation. Before this patch, these failures would cause the probe report to silently miss hits or hit the session timeout. A consumer of these reports could not tell whether the recorded hits were reliable or a partial trace cut short by an inspector-side failure. This patch surfaces those cases as a new `probe_failure` terminal `error` event on the report, with best-effort attribution to the implicated probe via `error.probe` and additional context on `error.details`. Together with `probe_timeout`, it marks the report as best-effort, and the probing process exits 1 in both cases. `probe_target_exit` and clean `completed`/`miss` reports continue to exit 0 because the recorded hits in those cases remain ground truth, so tooling can use the exit code as a quick trustworthiness signal. `error.message` now also contains actionable recovery hints whereever possible. The per-hit `error` is reshaped to `{ message, details? }` so that the per-hit and terminal errors share a top-level shape. Both fields are informative-only, only their top-level type is stable. Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
1 parent c0327d3 commit 32eca19

16 files changed

Lines changed: 774 additions & 138 deletions

doc/api/debugger.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ changes:
242242
`{ suffix, line, column? }` instead of an array. Each "hit" event carries a
243243
`location` field reporting the actual evaluation location. When the probe does not
244244
specify a column, it binds to the first executable column instead of defaulting to 1.
245+
- version: REPLACEME
246+
pr-url: https://github.com/nodejs/node/pull/63437
247+
description: Add `probe_failure` terminal `error` event for inspector-side mid-session
248+
failures, and add `error.details` for additional context on per-hit and terminal errors.
245249
-->
246250

247251
> Stability: 1 - Experimental
@@ -382,7 +386,10 @@ $ node inspect --json --probe cli.js:5 --expr 'rss' cli.js
382386
"value": 55443456,
383387
"description": "55443456"
384388
}
385-
// If the expression throws, "error" is present instead of "result".
389+
// If the probe expression throws, fails, or never completes, the entry
390+
// carries an `error` field instead of `result` with the shape
391+
// `{ message: string, details?: object }`. The `message` and `details`
392+
// content is informative-only and may change between releases.
386393
},
387394
{
388395
"probe": 0,
@@ -414,24 +421,40 @@ $ node inspect --json --probe cli.js:5 --expr 'rss' cli.js
414421
// "error": {
415422
// "code": "probe_target_exit",
416423
// "exitCode": 1,
417-
// "stderr": "[Error: boom]",
424+
// "stderr": "Error: boom",
418425
// "message": "Target exited with code 1 before probes: app.js:10"
419426
// }
420427
// }
428+
// 5. {
429+
// "event": "error",
430+
// "pending": [1],
431+
// "error": {
432+
// "code": "probe_failure",
433+
// "probe": 0,
434+
// "stderr": "...",
435+
// "message": "Target process exited during probe evaluation. If the failure repeats, review the probe expression.",
436+
// "details": { "lastCdpMethod": "Debugger.evaluateOnCallFrame" }
437+
// }
438+
// }
421439
}
422440
]
423441
}
424442
```
425443

426-
### Output and exit codes from the probed process
444+
### Output and exit codes
427445

428446
Probe mode only prints the final probe report to stdout, and otherwise silences
429447
stdout/stderr from the child process. When the probing session ends,
430-
`node inspect` typically exits with code `0` and prints a final report to
431-
stdout. If the child process exits with a non-zero code before the
432-
probe session ends, the final report records a terminal `error` event along
433-
with the exit code and captured child stderr. The probing process itself
434-
still exits with code `0` in this case.
448+
the probing process typically exits with code `0` and prints a final report to
449+
stdout. If the child process exits with a non-zero code before the probe
450+
session ends, or the probe session cannot complete for another reason, the
451+
final report records a terminal `error` event. The `error.code` distinguishes
452+
the cases (see the JSON shape example above).
453+
454+
When a terminal `error` event carries `code: 'probe_failure'`,
455+
recorded hits may be incomplete or out of order. In this case, `error.message`
456+
will contain recovery hints, and `error.probe` identifies the possible
457+
culprit probe on a best-effort basis to help guide debugging.
435458

436459
Invalid arguments and fatal launch or connect failures may cause the
437460
probing process to exit with a non-zero code and print an error message

0 commit comments

Comments
 (0)