Skip to content

Conversation

miguelmarcondesf
Copy link
Contributor

@miguelmarcondesf miguelmarcondesf commented Aug 30, 2025

Fix deduplication logic for inspect output when dealing with constructor names that contain custom tags, but checking for tag followed by lowercase characters, e.g: avoiding unnecessary tag Set from a constructor extended like FooSet(3) { 1, 2, 3 } from a util.inspect(new FooSet([1, 2, 3])) but keeping it for Settings(3) [Set] { 1, 2, 3 } from a util.inspect(new Settings([1, 2, 3]))

cc @BridgeAR

@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 Aug 30, 2025
Copy link

codecov bot commented Aug 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.29%. Comparing base (6428e2e) to head (47ddb0a).
⚠️ Report is 104 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #59687      +/-   ##
==========================================
- Coverage   89.95%   88.29%   -1.67%     
==========================================
  Files         667      702      +35     
  Lines      196813   206814   +10001     
  Branches    38425    39793    +1368     
==========================================
+ Hits       177038   182599    +5561     
- Misses      12200    16235    +4035     
- Partials     7575     7980     +405     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 99.89% <100.00%> (-0.07%) ⬇️

... and 146 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.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM with reverting the two cases / Highlighting the exact change where the change would be beneficial.

@miguelmarcondesf miguelmarcondesf force-pushed the improve-util-inspect-constructor branch from 744630c to 0a095ed Compare September 5, 2025 19:18
@BridgeAR BridgeAR added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 7, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 7, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@ljharb
Copy link
Member

ljharb commented Sep 8, 2025

I won't block this change, but I think that "sometimes omitting the [Set] output when the subclass name has 'Set' in it" is magic implicit behavior that makes the output less readable and more confusing. (also, that it doesn't apply for Map or other builtins adds to the inconsistency).

@BridgeAR
Copy link
Member

BridgeAR commented Sep 8, 2025

The intention when I added the [ClassName] was about making sure that we have that available somewhere for the user.
I think deduping is actually good :) (this only applies to built-ins anyway and as such also for Maps).

@ljharb
Copy link
Member

ljharb commented Sep 8, 2025

I agree deduping is good - but I don't think strings should be divisible, and FooSet and Set aren't duplicates, they're two distinct strings. If i name it class Settings extends Set it doesn't actually have "Set" in it in a human sense, but it would hit this logic too.

@BridgeAR
Copy link
Member

BridgeAR commented Sep 8, 2025

@ljharb it's a heuristic for the best behavior. We could guard against the case you mention, if you would like that (checking that the match is either at the end of the class name or that the next character is a capital letter).

@ljharb
Copy link
Member

ljharb commented Sep 8, 2025

That makes the heuristic less likely to be wrong, but also more magical and implicit, which doesn't seem worth it to me. I defer to you.

@miguelmarcondesf miguelmarcondesf force-pushed the improve-util-inspect-constructor branch from c14489f to 47ddb0a Compare September 13, 2025 15:24
@geeksilva97 geeksilva97 added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 18, 2025
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Sep 18, 2025
Copy link
Contributor

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - lib: update inspect output format for subclasses
   ⚠  - test: add inspect tests for null constructor scenarios
   ⚠  - test: update syntax error assertion in ESM loader test
   ⚠  - lib: revert tag exclusion for getClassBase
   ⚠  - lib: revert tag exclusion for getFunctionBase
   ⚠  - test: rename subclasses for Map and Promise in inspect tests
   ⚠  - lib: Update lib/internal/util/inspect.js
   ⚠  - test: enhance util.inspect assertions
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/17830830316

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

I am struggling understanding the test cases.

I believe we need a few scenarios:

  1. class SetAbc extends Set {}
  2. class AbcMap extends Map {}
  3. class MiddleErrorPart extends Error {}
  4. class Settings extends Set {}

These cases should cover all possible scenarios and the outcome would be:

1., 2., and 3. are all not having the fallback.
4. Shows the Set next to the constructor name.

Null prototypes work differently, since we can not reconstruct the class fully and they are not impacted.

} else {
const endPos = position + tag.length;
if (endPos !== constructor.length &&
constructor[endPos + 1] === constructor[endPos + 1].toLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

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

I had an off by one error writing this. It should be

Suggested change
constructor[endPos + 1] === constructor[endPos + 1].toLowerCase()) {
constructor[endPos] === constructor[endPos].toLowerCase()) {

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. request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants