Automattic / Automattic/mongoose

Using strict mode without 'throw' doesn't return errors for unknown properties

Open
#4,975 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
27.5k
Forks
4k
Avg merge
2d 5h
Merged PRs (30d)
32

Description

Creating an object with a key that isn't contained by the schema, then validating it with strict mode set to throw, raises an exception with the message it used a key path that isn't known, which is good.

When strict mode is set to true however, it doesn't raise an error at all for unknown properties. Is there a way to use the functionality from throw, but do it silent. I'd like to have the error added to the array of errors instead of raising an exception.

Is this possible?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing validation of an object with an unknown schema key under strict mode set to true and compare it with strict mode set to throw. Trace the validation entry point and determine whether the unknown-property error is added to the errors array without raising; done means strict true reports the error while remaining non-throwing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.