Skip to content

refactor: add ArgumentValidationError to @crawlee/core#3716

Open
B4nan wants to merge 1 commit into
v4from
feat/argument-validation-error
Open

refactor: add ArgumentValidationError to @crawlee/core#3716
B4nan wants to merge 1 commit into
v4from
feat/argument-validation-error

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented Jun 4, 2026

Adds a shared ArgumentValidationError (exported from @crawlee/core via errors.ts) for schema (zod) validation failures.

  • message — a plain, human-readable sentence naming the offending field and the value it received, e.g. Invalid string: must match pattern /^[A-Z]{2}$/ at `countryCode`, got `CZE` . Not a JSON dump.
  • issues — the structured zod issues, exposed directly on the error so consumers can branch on them without digging into cause.
  • cause — the original ZodError, kept for completeness.

The constructor takes (error: ZodError, value: unknown) and formats the message itself (the value is walked by each issue's path to surface the offending value).

Why

This is the foundation for migrating Crawlee's argument validation from ow to zod. The Apify SDK has just done the same migration and currently defines this class itself (apify-sdk-js#636) — once this lands and releases, the SDK will re-export it from @crawlee/core instead, so the two stay in lockstep.

Scope is intentionally just the error class (+ its formatter and a test) — no ow call sites are migrated here.

@crawlee/core already depends on zod; built in dependency order + lint + the new test all pass.

🤖 Generated with Claude Code

A shared error class for schema (zod) validation failures. Its `message` is a
human-readable sentence naming the offending field and the value it received,
while the structured zod `issues` are exposed directly on the error (and the
original `ZodError` on `cause`).

This is the foundation for migrating Crawlee's argument validation from `ow` to
`zod`; the Apify SDK re-exports it for the same purpose.
@B4nan B4nan added the adhoc Ad-hoc unplanned task added during the sprint. label Jun 4, 2026
@B4nan B4nan changed the title feat: add ArgumentValidationError to @crawlee/core refactor: add ArgumentValidationError to @crawlee/core Jun 4, 2026
@B4nan
Copy link
Copy Markdown
Member Author

B4nan commented Jun 4, 2026

Now I realized we wanted to drop this SDK<->crawlee dependency, but even in that case, we want the same error handling experience (as well as zod instead of ow), so I'd merge this in regarldess.

@janbuchar
Copy link
Copy Markdown
Contributor

Now I realized we wanted to drop this SDK<->crawlee dependency, but even in that case, we want the same error handling experience (as well as zod instead of ow), so I'd merge this in regarldess.

Agreed, but maybe we could put this in a package smaller than core? If SDK ends up depending on utils, for instance, nobody will bat an eye...

@B4nan
Copy link
Copy Markdown
Member Author

B4nan commented Jun 4, 2026

We might want to take a closer look at this, and maybe even introduce some @crawlee/common package for that. The utils one has some deps we might not want in the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants