Skip to content

Conversation

@yvele
Copy link
Contributor

@yvele yvele commented Nov 11, 2025

Fixes: #60683

  • Handle errors whose getters throw
  • Include the full error (stack, message, etc.) respecting inspect options
  • Fix indentation when getter throws

Previously, when a getter threw, only the message was output. Now inspect correctly outputs the full error according to the specified options.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Nov 11, 2025
@yvele
Copy link
Contributor Author

yvele commented Nov 11, 2025

Note that I based the behaviour from @legendecas comment in this related PR: #60139 (review)

I believe this is an improvement to the util.inspect that avoids throwing in debugging inspection.

@yvele yvele force-pushed the defensive-inspect-getter-error-message branch 2 times, most recently from ab97c2a to 09d8f0b Compare November 11, 2025 19:47
@yvele yvele force-pushed the defensive-inspect-getter-error-message branch from 89f0e53 to 9b05e4e Compare November 12, 2025 13:53
Copy link
Contributor Author

@yvele yvele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduh95 @ljharb this is way more straighforward.
I fully rely on inspect to get the error description.

The error not only shows the error message but the whole (indented) stack:

{
  foo: [Getter: <Inspection threw (Error: Oops
    at get foo (/foo/node_modules/foo.js:2:7)
    at get bar (/foo/node_modules/bar.js:827:30))>]
}

I think that looks pretty nice and explicit👍

What do you think?

@yvele yvele requested review from aduh95 and ljharb November 18, 2025 18:59
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the much simpler implementation

@aduh95
Copy link
Contributor

aduh95 commented Nov 22, 2025

nit: if you could add a test with recursion (i.e. a case where the inspect(err) will itself contain throwing a getter, which itself contains a throwing getter, etc.) to make sure we're handling that, that be nice

@codecov
Copy link

codecov bot commented Nov 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.54%. Comparing base (fc203b3) to head (dd6be92).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60684      +/-   ##
==========================================
- Coverage   88.55%   88.54%   -0.02%     
==========================================
  Files         703      703              
  Lines      208259   208259              
  Branches    40178    40164      -14     
==========================================
- Hits       184425   184395      -30     
- Misses      15855    15867      +12     
- Partials     7979     7997      +18     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 99.67% <100.00%> (ø)

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yvele yvele requested a review from aduh95 November 24, 2025 10:16
@yvele yvele force-pushed the defensive-inspect-getter-error-message branch from e0cae36 to 04bb6b2 Compare November 24, 2025 13:32
@yvele yvele force-pushed the defensive-inspect-getter-error-message branch from ea37cc0 to 83db54c Compare November 25, 2025 08:29
@yvele yvele force-pushed the defensive-inspect-getter-error-message branch from df7e577 to a683626 Compare November 25, 2025 11:06
@yvele yvele requested a review from aduh95 November 25, 2025 11:07
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Nov 25, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 25, 2025
@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 25, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 25, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 27, 2025
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 27, 2025
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/60684
✔  Done loading data for nodejs/node/pull/60684
----------------------------------- PR info ------------------------------------
Title      util: safely inspect getter errors whose message throws (#60684)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     yvele:defensive-inspect-getter-error-message -> nodejs:main
Labels     util, author ready, needs-ci
Commits    16
 - util: safely inspect getter errors whose message throws
 - fixup! util: add test cases with getters throwing uncommon values
 - fixup! util: handle uncommon thrown errors
 - fixup! util: ESLint exception line styling
 - fixup! util: add test case with getter throwing undefined
 - fixup! util: implement consistent `inspect(err)`
 - fixup! util: improve test readability
 - fixup! util: rely in inspect to describe error
 - fixup! util: typo in test comment
 - fixup! util: handle inspect options
 - fixup! util: fix error catch indentation
 - fixup! util: add infinite recursion test case
 - fixup! util: improve test readability with an array
 - fixup! util: improve recursive test readability
 - fixup! util: add depth 2 test cases
 - fixup! util: add comment explaining stackTraceLimit override in test
Committers 1
 - Yves M <4225430+yvele@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/60684
Fixes: https://github.com/nodejs/node/issues/60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/60684
Fixes: https://github.com/nodejs/node/issues/60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Tue, 11 Nov 2025 19:27:57 GMT
   ✔  Approvals: 1
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/60684#pullrequestreview-3504941867
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2025-11-27T09:36:15Z: https://ci.nodejs.org/job/node-test-pull-request/70329/
- Querying data for job/node-test-pull-request/70329/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 60684
From https://github.com/nodejs/node
 * branch                  refs/pull/60684/merge -> FETCH_HEAD
✔  Fetched commits as ce29481a527e..dd6be927896a
--------------------------------------------------------------------------------
[main e8271737e0] util: safely inspect getter errors whose message throws
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Tue Nov 11 20:46:56 2025 +0100
 2 files changed, 25 insertions(+), 1 deletion(-)
[main 035cd606bc] fixup! util: add test cases with getters throwing uncommon values
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Wed Nov 12 10:53:08 2025 +0100
 1 file changed, 54 insertions(+), 1 deletion(-)
[main 95baef3772] fixup! util: handle uncommon thrown errors
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Wed Nov 12 11:07:02 2025 +0100
 2 files changed, 8 insertions(+), 7 deletions(-)
[main 043eb8ec04] fixup! util: ESLint exception line styling
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Wed Nov 12 11:11:02 2025 +0100
 1 file changed, 3 insertions(+), 3 deletions(-)
[main 9cb7b3096c] fixup! util: add test case with getter throwing undefined
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Wed Nov 12 11:20:56 2025 +0100
 1 file changed, 7 insertions(+)
[main 2de1b535df] fixup! util: implement consistent `inspect(err)`
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Wed Nov 12 13:22:02 2025 +0100
 2 files changed, 100 insertions(+), 53 deletions(-)
[main 889242c169] fixup! util: improve test readability
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Wed Nov 12 14:07:55 2025 +0100
 1 file changed, 3 insertions(+), 3 deletions(-)
[main ba780b4546] fixup! util: rely in inspect to describe error
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Tue Nov 18 19:53:14 2025 +0100
 2 files changed, 24 insertions(+), 46 deletions(-)
[main 30f22a9131] fixup! util: typo in test comment
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Sat Nov 22 15:04:46 2025 +0100
 1 file changed, 1 insertion(+), 1 deletion(-)
[main 979c15a4bb] fixup! util: handle inspect options
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Mon Nov 24 10:43:34 2025 +0100
 2 files changed, 153 insertions(+), 14 deletions(-)
[main d7df413558] fixup! util: fix error catch indentation
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Mon Nov 24 10:53:54 2025 +0100
 2 files changed, 16 insertions(+), 18 deletions(-)
[main ddd68cef77] fixup! util: add infinite recursion test case
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Mon Nov 24 11:15:10 2025 +0100
 1 file changed, 37 insertions(+)
[main 91bbcecd7a] fixup! util: improve test readability with an array
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Mon Nov 24 14:27:42 2025 +0100
 1 file changed, 49 insertions(+), 46 deletions(-)
[main 4602a59137] fixup! util: improve recursive test readability
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Tue Nov 25 09:18:32 2025 +0100
 1 file changed, 29 insertions(+), 100 deletions(-)
[main d4bd6e4ed2] fixup! util: add depth 2 test cases
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Tue Nov 25 11:58:52 2025 +0100
 1 file changed, 39 insertions(+), 25 deletions(-)
[main 0036451488] fixup! util: add comment explaining stackTraceLimit override in test
 Author: Yves M <4225430+yvele@users.noreply.github.com>
 Date: Tue Nov 25 12:13:48 2025 +0100
 1 file changed, 2 insertions(+)
   ✔  Patches applied
There are 16 commits in the PR. Attempting autorebase.
(node:2267) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
util: safely inspect getter errors whose message throws

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD b31fcfc8bb] util: safely inspect getter errors whose message throws
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Tue Nov 11 20:46:56 2025 +0100
2 files changed, 25 insertions(+), 1 deletion(-)
Rebasing (3/32)
Rebasing (4/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: add test cases with getters throwing uncommon values

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 6125792641] fixup! util: add test cases with getters throwing uncommon values
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Wed Nov 12 10:53:08 2025 +0100
1 file changed, 54 insertions(+), 1 deletion(-)
Rebasing (5/32)
Rebasing (6/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: handle uncommon thrown errors

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 01545dde98] fixup! util: handle uncommon thrown errors
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Wed Nov 12 11:07:02 2025 +0100
2 files changed, 8 insertions(+), 7 deletions(-)
Rebasing (7/32)
Rebasing (8/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: ESLint exception line styling

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 0365e789cb] fixup! util: ESLint exception line styling
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Wed Nov 12 11:11:02 2025 +0100
1 file changed, 3 insertions(+), 3 deletions(-)
Rebasing (9/32)
Rebasing (10/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: add test case with getter throwing undefined

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD c5ea56f008] fixup! util: add test case with getter throwing undefined
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Wed Nov 12 11:20:56 2025 +0100
1 file changed, 7 insertions(+)
Rebasing (11/32)
Rebasing (12/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: implement consistent inspect(err)

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD d622172a5c] fixup! util: implement consistent inspect(err)
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Wed Nov 12 13:22:02 2025 +0100
2 files changed, 100 insertions(+), 53 deletions(-)
Rebasing (13/32)
Rebasing (14/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: improve test readability

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 7d6eb8e369] fixup! util: improve test readability
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Wed Nov 12 14:07:55 2025 +0100
1 file changed, 3 insertions(+), 3 deletions(-)
Rebasing (15/32)
Rebasing (16/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: rely in inspect to describe error

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 76cb19b135] fixup! util: rely in inspect to describe error
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Tue Nov 18 19:53:14 2025 +0100
2 files changed, 24 insertions(+), 46 deletions(-)
Rebasing (17/32)
Rebasing (18/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: typo in test comment

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD e0afa9da38] fixup! util: typo in test comment
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Sat Nov 22 15:04:46 2025 +0100
1 file changed, 1 insertion(+), 1 deletion(-)
Rebasing (19/32)
Rebasing (20/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: handle inspect options

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 2bea208dfe] fixup! util: handle inspect options
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Mon Nov 24 10:43:34 2025 +0100
2 files changed, 153 insertions(+), 14 deletions(-)
Rebasing (21/32)
Rebasing (22/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: fix error catch indentation

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD ae714554c6] fixup! util: fix error catch indentation
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Mon Nov 24 10:53:54 2025 +0100
2 files changed, 16 insertions(+), 18 deletions(-)
Rebasing (23/32)
Rebasing (24/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: add infinite recursion test case

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 869050c531] fixup! util: add infinite recursion test case
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Mon Nov 24 11:15:10 2025 +0100
1 file changed, 37 insertions(+)
Rebasing (25/32)
Rebasing (26/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: improve test readability with an array

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 4a75664cf8] fixup! util: improve test readability with an array
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Mon Nov 24 14:27:42 2025 +0100
1 file changed, 49 insertions(+), 46 deletions(-)
Rebasing (27/32)
Rebasing (28/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: improve recursive test readability

see #60684 (comment)

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD e0839c0d7a] fixup! util: improve recursive test readability
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Tue Nov 25 09:18:32 2025 +0100
1 file changed, 29 insertions(+), 100 deletions(-)
Rebasing (29/32)
Rebasing (30/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: add depth 2 test cases

See #60684 (comment)

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 68959fdf5f] fixup! util: add depth 2 test cases
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Tue Nov 25 11:58:52 2025 +0100
1 file changed, 39 insertions(+), 25 deletions(-)
Rebasing (31/32)
Rebasing (32/32)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
fixup! util: add comment explaining stackTraceLimit override in test

See https://github.com/nodejs/node/pull/60684/files#r2553166047

PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>

[detached HEAD 58d62fbe39] fixup! util: add comment explaining stackTraceLimit override in test
Author: Yves M <4225430+yvele@users.noreply.github.com>
Date: Tue Nov 25 12:13:48 2025 +0100
1 file changed, 2 insertions(+)
Successfully rebased and updated refs/heads/main.

ℹ Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/19733585643

@aduh95 aduh95 added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Nov 27, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 27, 2025
@nodejs-github-bot nodejs-github-bot merged commit ca5956c into nodejs:main Nov 27, 2025
86 of 87 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in ca5956c

@yvele yvele deleted the defensive-inspect-getter-error-message branch November 27, 2025 12:52
targos pushed a commit that referenced this pull request Nov 29, 2025
PR-URL: #60684
Fixes: #60683
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

util.inspect crashes with a getter whose error.message throws

4 participants