Skip to content

Commit 3553a34

Browse files
authored
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> PR-URL: #63437 Refs: #62713 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Jan Martin <jan.krems@gmail.com>
1 parent e11b945 commit 3553a34

16 files changed

Lines changed: 798 additions & 154 deletions

doc/api/debugger.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ added:
237237
- v26.1.0
238238
- v24.16.0
239239
changes:
240+
- version: REPLACEME
241+
pr-url: https://github.com/nodejs/node/pull/63437
242+
description: Add `probe_failure` terminal `error` event for inspector-side mid-session
243+
failures, and `error.details` for additional context on per-hit and terminal errors.
240244
- version: v26.2.0
241245
pr-url: https://github.com/nodejs/node/pull/63286
242246
description: JSON report schema bumped to v2. Probe `target` is now
@@ -383,7 +387,10 @@ $ node inspect --json --probe cli.js:5 --expr 'rss' cli.js
383387
"value": 55443456,
384388
"description": "55443456"
385389
}
386-
// If the expression throws, "error" is present instead of "result".
390+
// If the probe expression throws, fails, or never completes, the entry
391+
// carries an `error` field instead of `result` with the shape
392+
// `{ message: string, details?: object }`. The `message` and `details`
393+
// content is informational only and may change between releases.
387394
},
388395
{
389396
"probe": 0,
@@ -415,24 +422,40 @@ $ node inspect --json --probe cli.js:5 --expr 'rss' cli.js
415422
// "error": {
416423
// "code": "probe_target_exit",
417424
// "exitCode": 1,
418-
// "stderr": "[Error: boom]",
425+
// "stderr": "Error: boom",
419426
// "message": "Target exited with code 1 before probes: app.js:10"
420427
// }
421428
// }
429+
// 5. {
430+
// "event": "error",
431+
// "pending": [1],
432+
// "error": {
433+
// "code": "probe_failure",
434+
// "probe": 0,
435+
// "stderr": "...",
436+
// "message": "Target process exited during probe evaluation before probes: app.js:12. If the failure repeats, review the probe expression.",
437+
// "details": { "lastCdpMethod": "Debugger.evaluateOnCallFrame" }
438+
// }
439+
// }
422440
}
423441
]
424442
}
425443
```
426444

427-
### Output and exit codes from the probed process
445+
### Output and exit codes
428446

429447
Probe mode only prints the final probe report to stdout, and otherwise silences
430448
stdout/stderr from the child process. When the probing session ends,
431-
`node inspect` typically exits with code `0` and prints a final report to
432-
stdout. If the child process exits with a non-zero code before the
433-
probe session ends, the final report records a terminal `error` event along
434-
with the exit code and captured child stderr. The probing process itself
435-
still exits with code `0` in this case.
449+
the probing process typically exits with code `0` and prints a final report to
450+
stdout. If the child process exits with a non-zero code before the probe
451+
session ends, or the probe session cannot complete for another reason, the
452+
final report records a terminal `error` event.
453+
454+
When `error.code` is `'probe_failure'` or `'probe_timeout'`, the probing process
455+
exits with a non-zero code, indicating recorded hits may be incomplete.
456+
In this case, `error.message` will contain recovery hints, and `error.probe`,
457+
when present, is an index into the report's `probes` array that identifies
458+
the possible culprit probe on a best-effort basis to help guide debugging.
436459

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

0 commit comments

Comments
 (0)