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

How to run error handling middleware on validateSync()? #8703

Open
vkarpov15 opened this issue Mar 21, 2020 · 3 comments · May be fixed by #12372
Open

How to run error handling middleware on validateSync()? #8703

vkarpov15 opened this issue Mar 21, 2020 · 3 comments · May be fixed by #12372
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Right now we skip async validators on validateSync(), but the way we determine if a validator is async is based on the number of arguments. Since error handling middleware must take 3 arguments, validateSync() will never run error handling middleware #4885

Re: #4885

@vkarpov15 vkarpov15 added the enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature label Mar 21, 2020
@vkarpov15 vkarpov15 added this to the Parking Lot milestone Mar 21, 2020
@hasezoey
Copy link
Collaborator

is this still a issue because doValidate uses isAsyncFunction which checks the function prototype instead of argument length?

@Uzlopak
Copy link
Collaborator

Uzlopak commented Aug 31, 2022

I think a unit test, which proves that the error handling middleware is called should prove that this issue is done.

@hasezoey
Copy link
Collaborator

hasezoey commented Sep 1, 2022

i have opened up #12371 which address some of this issue

i have noticed that validateSync does not trigger any hooks, even if they are normal sync functions, so i made #12372 as a draft for now - if it is wanted that this function to not execute hooks, please close the PR (stating that)

PS: the documentation does not state that validateSync does not execute hooks, so it should maybe be mentioned if this is not a wanted feature (https://mongoosejs.com/docs/api.html#document_Document-validateSync)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants