refactor: add ArgumentValidationError to @crawlee/core#3716
Open
B4nan wants to merge 1 commit into
Open
Conversation
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.
Member
Author
|
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. |
Contributor
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... |
Member
Author
|
We might want to take a closer look at this, and maybe even introduce some |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a shared
ArgumentValidationError(exported from@crawlee/coreviaerrors.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 intocause.cause— the originalZodError, kept for completeness.The constructor takes
(error: ZodError, value: unknown)and formats the message itself (thevalueis walked by each issue'spathto surface the offending value).Why
This is the foundation for migrating Crawlee's argument validation from
owtozod. 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/coreinstead, so the two stay in lockstep.Scope is intentionally just the error class (+ its formatter and a test) — no
owcall sites are migrated here.@crawlee/corealready depends onzod; built in dependency order + lint + the new test all pass.🤖 Generated with Claude Code