refactor: move describe helper to @crawlee/utils as inspectValue#3586
refactor: move describe helper to @crawlee/utils as inspectValue#3586
describe helper to @crawlee/utils as inspectValue#3586Conversation
| if (typeof value === 'object' && value !== null) { | ||
| return value.constructor.name; | ||
| } | ||
| return String(value); |
There was a problem hiding this comment.
Perhaps we could make the function a bit beefier? A bit like https://nodejs.org/api/util.html#utilinspectobject-options
There was a problem hiding this comment.
good idea, I used inject as a fallback if contructor.name not available
| /** | ||
| * 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
+1 for internal. IIRC, we are exporting it because stuff like this can be genuinely useful for debugging or providing good error messages.
There was a problem hiding this comment.
yes we already use it in service locator in ServiceConflictError ([Object object])
l2ysho
left a comment
There was a problem hiding this comment.
fixed tests (finally)
| beforeEach(async () => { | ||
| const { serviceLocator } = await import('../packages/core/src/service_locator.js'); | ||
| serviceLocator.reset(); | ||
| }); |
There was a problem hiding this comment.
fixing mocking problem in test/utils/cpu-infoV2.test.ts and test/utils/memory-infoV2.test.ts
B4nan
left a comment
There was a problem hiding this comment.
looks good, lets just update the PR title/description
describe helper to @crawlee/utils packagedescribe helper to @crawlee/utils as inspectValue
This reverts commit 78d4e24.
|
@janbuchar I will wait for you as you self-requested :] |
Summary
Extracts the ad-hoc
describe()helper that was inlined insideServiceConflictErrorinto a shared, reusable utility exported from@crawlee/utilsasinspectValue.packages/utils/src/internals/debug.ts→inspectValue(value):returns
value.constructor.namewhen available, otherwise falls back toutil.inspectwith sensible defaults (depth: 0,compact: true,maxStringLength: 64, no colors). Thiscorrectly handles
null/undefinedand other cases where the previous helper would have returned"null"/"undefined"viaString()— acceptable, but now uniform with how we label othervalues.
describetoinspectValue—describeServiceConflictErrornow delegates toinspectValueinstead of carrying its own inline implementation.test/vitest.setup.tsto importserviceLocatordynamically insidebeforeEachto avoid the eager import ordering issue surfaced by the change.Closes #3497