Skip to content

chore: unify argument validation to zod - #3935

Draft
vladfrangu wants to merge 6 commits into
v4from
chore/unify-to-zod
Draft

chore: unify argument validation to zod#3935
vladfrangu wants to merge 6 commits into
v4from
chore/unify-to-zod

Conversation

@vladfrangu

Copy link
Copy Markdown
Member

Replaces the remaining ow-based argument validation with zod across all packages and reworks how validation results are consumed.

Closes #3716

What changed

  • ow is gone — every argument check now goes through parseArgument(value, schema) from @crawlee/utils, backed by shared zod schemas.
  • Error messages follow refactor: add ArgumentValidationError to @crawlee/core #3716ArgumentValidationError renders the zod issue message plus the offending field path and the received value (e.g. Invalid input: expected number at `maxConcurrency`, got `NaN` ). The raw ZodError is exposed as a typed cause, and its issues directly on the error.
  • Parse results are used everywhere — option defaults moved from destructuring into the schemas (.default(...)), and call sites destructure the typed parse result. parseArgument returns TValue & z.output<TSchema>, so call sites keep their declared TS types while gaining the defaults.
  • Schemas are built once — all per-call schemas are hoisted to module scope; crawler/launcher classes build their strict options schema once as a static optionsSchema next to optionsShape.
  • Specific validators instead of anyObject — class-typed options use z.instanceof(...) (BaseHttpClient, Configuration, EventManager, Snapshotter, KeyValueStore), interface-typed ones use duck-typed objectWithKeys validators (storageBackend, requestManager, logger).

Notes

  • Custom HTTP clients must now extend BaseHttpClient from @crawlee/http-client rather than just implementing the interface (all shipped clients already do; LazyDefaultHttpClient was converted).
  • One caveat of consuming parse results: zod object schemas return a pruned plain copy, so options holding class instances are validated with passthrough schemas (z.custom-based) to keep their prototypes — there are comments at the relevant schemas.
  • Fixes a few latent optionsShape gaps that the strict schemas surfaced: requestManager on BasicCrawler, ignoreIframes/ignoreShadowRoots on BrowserCrawler.

@vladfrangu
vladfrangu changed the base branch from master to v4 July 30, 2026 11:36
@vladfrangu
vladfrangu force-pushed the chore/unify-to-zod branch 2 times, most recently from 48101f6 to acb4aab Compare July 30, 2026 13:10
@vladfrangu vladfrangu added the t-tooling Issues with this label are in the ownership of the tooling team. label Aug 4, 2026
…gument results

Message format matches #3716: the zod issue message plus the offending
field path and the received value. parseArgument drops the label
argument and returns the parsed (default-applied) value, typed as the
input intersected with the schema output.
…nce validators

Options are now destructured from the parse result with defaults
declared in the schemas, all per-call schemas are hoisted to module
scope, and instance-like options are validated with specific
validators (instanceof for classes, objectWithKeys for interfaces)
instead of anyObject.
Crawler and launcher classes build their strict options schema once as
a static (optionsSchema) and consume the parse result. Adds missing
optionsShape entries (requestManager, ignoreIframes, ignoreShadowRoots)
and makes LazyDefaultHttpClient extend BaseHttpClient so it passes the
new instanceof validation.
Consumers were mixing the class from @crawlee/http-client with the
same-named interface from @crawlee/types, producing aliased duplicate
imports (BaseHttpClient_2) in the public API reports. Since httpClient
options are now validated with instanceof, the class is the actual
contract — import it everywhere. Only the definition site keeps the
interface (the class implements it).
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.

2 participants