FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix undefined descriptor error in property formatting by siaeyy · Pull Request #60724 · nodejs/node · GitHub

/ node Public

Fix undefined descriptor error in property formatting - #60724

Closed
siaeyy wants to merge 2 commits into
nodejs:mainfrom
siaeyy:fix_undefined_descriptor_v2
Closed

Fix undefined descriptor error in property formatting#60724
siaeyy wants to merge 2 commits into
nodejs:mainfrom
siaeyy:fix_undefined_descriptor_v2

Conversation

siaeyy commented Nov 15, 2025

Copy link
Copy Markdown
Contributor

Fixes: #60717

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 15, 2025

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The change and test is LGTM.

After giving it some more thought, I just lean on not printing these when the properties are not own properties. That aligns more with other inspected parts.

@ljharb since you often have an opinion about inspect, what is your take on it?

Copy link
Copy Markdown
Member

@siaeyy do you mind changing the code as follows instead:

diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 83c254c3d6c..813c7eec659 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -1955,14 +1955,14 @@ function formatError(err, constructor, tag, ctx, keys) {
   }
   name ??= 'Error';
 
-  if ('cause' in err &&
+  if (Object.hasOwn(err, 'cause') &&
       (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'cause'))) {
     ArrayPrototypePush(keys, 'cause');
   }
 
   // Print errors aggregated into AggregateError
   try {
-    const errors = err.errors;
+    const errors = Object.hasOwn(err, 'errors') ? err.errors : undefined;
     if (ArrayIsArray(errors) &&
       (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'errors'))) {
       ArrayPrototypePush(keys, 'errors');

That way only own properties are handled as with other objects. The test should still pass with the new change.

ljharb commented Dec 1, 2025

Copy link
Copy Markdown
Member

I think that makes sense, since both cause and errors will only ever be own properties.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 15, 2025
Error's cause and errors properties would be visible even if these
were not own properties. This is changed to align with all other
parts of the inspect handling.

Fixes: nodejs#60717
Closes: nodejs#60724
siaeyy closed this Dec 20, 2025

siaeyy commented Dec 20, 2025

Copy link
Copy Markdown
Contributor Author

There is already another pr that fixes the issue.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 throws when given a ZodError

4 participants


Back | FazBrowse Home | New Git URL