Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserialize doesn't throw errors if beforeDeserialize passes errors to callback #181

Open
yifanwww opened this issue Sep 20, 2023 · 2 comments

Comments

@yifanwww
Copy link

yifanwww commented Sep 20, 2023

This doc implies that in beforeDeserialize we can do callback(err) to stop the deserialization and get a throwed error, just like we do it in afterDeserialize.

However, the real behavior is different. It behaves like the field/prop doesn't exist and just skips it.

For example:

// example 1

const schema = createSimpleSchema({
    a: primitive({ beforeDeserialize: (done) => done('err') }),
    b: raw({ beforeDeserialize: (done) => done('err') }),
    c: identifier({ beforeDeserialize: (done) => done('err') }),
    d: date({ beforeDeserialize: (done) => done('err') }),
});

deserialize(schema, { a: 1, b: 1, c: 1, d: 1 });

// example 2

const schema = createSimpleSchema({
    a: object(
        createSimpleSchema({
            b: primitive({ beforeDeserialize: (done) => done('err') }),
        }),
    ),
});

deserialize(schema, { a: { b: 1 } });

We would expect that it should throw an error err, but it doesn't.

I checked the code, here it just ignores any errors from beforeDeserialize, is there any reason or is it a bug?

@mweststrate
Copy link
Member

mweststrate commented Sep 20, 2023 via email

@1R053
Copy link
Collaborator

1R053 commented May 17, 2024

actually the error handling here is intentionally graceful. The consequence of an error is just a missing datapoint in the json, not a forcefully broken process. Otherwise it would not be possible to parse the whole dataset and identify all issues in one go.

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

No branches or pull requests

3 participants