-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Fix undefined descriptor error in property formatting #60724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
BridgeAR
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
|
@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. |
|
I think that makes sense, since both |
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
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
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. As drive-by I changed an array to a set for faster lookup in assert. Fixes: nodejs#60717 Closes: nodejs#60724
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
|
There is already another pr that fixes the issue. |
Fixes: #60717