Skip to content

refactor: move describe helper to @crawlee/utils as inspectValue#3586

Merged
l2ysho merged 6 commits intov4from
3497-move-describe-helper-to-utils-package
Apr 27, 2026
Merged

refactor: move describe helper to @crawlee/utils as inspectValue#3586
l2ysho merged 6 commits intov4from
3497-move-describe-helper-to-utils-package

Conversation

@l2ysho
Copy link
Copy Markdown
Contributor

@l2ysho l2ysho commented Apr 21, 2026

Summary

Extracts the ad-hoc describe() helper that was inlined inside ServiceConflictError into a shared, reusable utility exported from @crawlee/utils as inspectValue.

  • New util packages/utils/src/internals/debug.tsinspectValue(value):
    returns value.constructor.name when available, otherwise falls back to util.inspect with sensible defaults (depth: 0, compact: true, maxStringLength: 64, no colors). This
    correctly handles null/undefined and other cases where the previous helper would have returned "null"/"undefined" via String() — acceptable, but now uniform with how we label other
    values.
  • Rename from describe to inspectValuedescribe
  • ServiceConflictError now delegates to inspectValue instead of carrying its own inline implementation.
  • Test setup: switched test/vitest.setup.ts to import serviceLocator dynamically inside beforeEach to avoid the eager import ordering issue surfaced by the change.

Closes #3497

@l2ysho l2ysho requested a review from janbuchar April 21, 2026 08:50
@l2ysho l2ysho added the t-tooling Issues with this label are in the ownership of the tooling team. label Apr 21, 2026
@l2ysho l2ysho self-assigned this Apr 21, 2026
@l2ysho l2ysho requested review from B4nan and barjin April 21, 2026 08:52
Copy link
Copy Markdown
Member

@barjin barjin left a comment

Choose a reason for hiding this comment

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

lgtm, thank you @l2ysho 👍

I'm thinking whether the describe name is not a bit too vague (now that it's an exported symbol), but I'll leave that up to you.

Comment thread packages/utils/src/internals/debug.ts Outdated
Comment on lines +64 to +67
if (typeof value === 'object' && value !== null) {
return value.constructor.name;
}
return String(value);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we could make the function a bit beefier? A bit like https://nodejs.org/api/util.html#utilinspectobject-options

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good idea, I used inject as a fallback if contructor.name not available

Comment thread packages/utils/src/internals/debug.ts Outdated
Comment on lines +59 to +63
/**
* Returns a human-readable string representation of an unknown value.
* For objects, returns the constructor name; for primitives, returns `String(value)`.
*/
export function describe(value: unknown): string {
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.

let's mark this as @internal, and I would also vote for a less generic name.

btw are we exporting this just because or do we have a place where we want to use it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 for internal. IIRC, we are exporting it because stuff like this can be genuinely useful for debugging or providing good error messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes we already use it in service locator in ServiceConflictError ([Object object])

@janbuchar janbuchar self-requested a review April 24, 2026 12:31
Copy link
Copy Markdown
Contributor Author

@l2ysho l2ysho left a comment

Choose a reason for hiding this comment

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

fixed tests (finally)

Comment thread test/vitest.setup.ts
Comment on lines +3 to 6
beforeEach(async () => {
const { serviceLocator } = await import('../packages/core/src/service_locator.js');
serviceLocator.reset();
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixing mocking problem in test/utils/cpu-infoV2.test.ts and test/utils/memory-infoV2.test.ts

@l2ysho l2ysho requested a review from B4nan April 24, 2026 13:59
Copy link
Copy Markdown
Member

@B4nan B4nan left a comment

Choose a reason for hiding this comment

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

looks good, lets just update the PR title/description

@l2ysho l2ysho changed the title refactor: move describe helper to @crawlee/utils package refactor: move describe helper to @crawlee/utils as inspectValue Apr 24, 2026
@l2ysho
Copy link
Copy Markdown
Contributor Author

l2ysho commented Apr 24, 2026

@janbuchar I will wait for you as you self-requested :]

@l2ysho l2ysho merged commit 55986bb into v4 Apr 27, 2026
6 checks passed
@l2ysho l2ysho deleted the 3497-move-describe-helper-to-utils-package branch April 27, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants