Skip to content

util: fix inspect crash when getter returns a function - #64856

Closed
NeverBetterEnough wants to merge 1 commit into
nodejs:mainfrom
NeverBetterEnough:fix/util-inspect-getter-function
Closed

util: fix inspect crash when getter returns a function#64856
NeverBetterEnough wants to merge 1 commit into
nodejs:mainfrom
NeverBetterEnough:fix/util-inspect-getter-function

Conversation

@NeverBetterEnough

Copy link
Copy Markdown

When a property getter returns a function, formatProperty incorrectly
routes the function value to formatPrimitive, which does not handle
functions and falls through to Symbol.prototype.toString(), causing a
TypeError.

Fix by treating getter-returned functions the same as getter-returned
objects in formatProperty, routing them through formatValue which
properly formats functions.

Before (broken):

getFunction: [Getter: <Inspection threw (TypeError: ...)>]

After (fixed):

getFunction: [Getter] [Function: fn]

Changes:

  • lib/internal/util/inspect.js: +1/-1 — added || typeof tmp === 'function' to the object-branch condition
  • test/parallel/test-util-inspect.js: +20 — regression test reproducing the scenario

Fixes: #64838

When a property getter returns a function, formatProperty incorrectly
routes the function value to formatPrimitive, which does not handle
functions and falls through to Symbol.prototype.toString(), causing a
TypeError.

Fix by treating getter-returned functions the same as getter-returned
objects in formatProperty, routing them through formatValue which
properly formats functions.

Before (broken):
  getFunction: [Getter: <Inspection threw (TypeError: ...)>]

After (fixed):
  getFunction: [Getter] [Function: fn]

Fixes: nodejs#64838
@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 Jul 31, 2026
@bakkot

bakkot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Dupe of #64839

@avivkeller avivkeller closed this Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 fails to represent a function returned from a getter

4 participants