parse-server
parse-server copied to clipboard
Fix invalid date error in beforeSave hook
New Pull Request Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am creating this PR in reference to an issue.
Issue Description
Saving an object with invalid ISO date throws an error instead of rejecting the Parse.Object.save() promise.
Related issue: closes #7192
Approach
(tdb, just the failing test case for now)
TODOs before merging
- [x] Add test cases
- [ ] Add entry to changelog
- [ ] Add new Parse Error codes to Parse JS SDK
The failing test reveals another issue, are two different error messages for the same error:
Failures:
1) beforeSave hooks rejects saving with invalid iso date and beforeSave hook (#7192)
Message:
Expected a promise to be rejected with ParseError: 111 This is not a valid Date but it was rejected with Error: Tried to encode an invalid date..
Stack:
Error
at <Jasmine>
at UserContext.<anonymous> (/root/parse-server/spec/CloudCode.spec.js:1833:37)
at <Jasmine>
at /root/parse-server/spec/helper.js:192:7
at processTicksAndRejections (node:internal/process/task_queues:93:5)
Message:
Unhandled promise rejection: Error: Tried to encode an invalid date.
Stack:
Error: Tried to encode an invalid date.
at encode (/root/parse-server/node_modules/parse/lib/node/encode.js:85:13)
at _default (/root/parse-server/node_modules/parse/lib/node/encode.js:132:10)
at SetOp.toJSON (/root/parse-server/node_modules/parse/lib/node/ParseOp.js:155:32)
at ParseObjectSubclass._getSaveJSON (/root/parse-server/node_modules/parse/lib/node/ParseObject.js:485:61)
at success (/root/parse-server/lib/triggers.js:385:45)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
Message:
Failed: There were open connections to the server left after the test finished
Stack:
Error: Failed: There were open connections to the server left after the test finished
at <Jasmine>
at afterLogOut (/root/parse-server/spec/helper.js:200:7)
⚠️ Important change for merging PRs from Parse Server 5.0 onwards!
We are planning to release the first beta version of Parse Server 5.0 in October 2021.
If a PR contains a breaking change and is not merged before the beta release of Parse Server 5.0, it cannot be merged until the end of 2022. Instead it has to follow the Deprecation Policy and phase-in breaking changes to be merged during the course of 2022.
One of the most voiced community feedbacks was the demand for predictability in breaking changes to make it easy to upgrade Parse Server. We have made a first step towards this by introducing the Deprecation Policy in February 2021 that assists to phase-in breaking changes, giving developers time to adapt. We will follow-up with the introduction of Release Automation and a branch model that will allow breaking changes only with a new major release, scheduled for the beginning of each calendar year.
We understand that some PRs are a long time in the making and we very much appreciate your contribution. We want to make it easy for PRs that contain a breaking change and were created before the introduction of the Deprecation Policy. These PRs can be merged with a breaking change without being phased-in before the beta release of Parse Server 5.0. We are making this exception because we appreciate that this is a time of transition that requires additional effort from contributors to adapt. We encourage everyone to prepare their PRs until the end of September and account for review time and possible adaptions.
If a PR contains a breaking change and should be merged before the beta release, please mention @parse-community/server-maintenance and we will coordinate with you to merge the PR.
Thanks for your contribution and support during this transition to Parse Server release automation!