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

fix: Remove validation error handler option error from various methods of Parse.Object #2445

Merged
merged 4 commits into from
Feb 16, 2025

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Feb 12, 2025

Pull Request

Issue

You can pass an option in set to handle validation errors. The problem is this option isn't well documented and isn't widely used. This method of error handling is called backbone and was removed in 2.0.0. There are two errors (invalid key name and invalid acl) that are being checked. This could potentially be a breaking change if a user is setting invalid fields and never saving as saving would throw the errors.

object.set('$$$', 'o_O', {
  error: function (thisObj, err) {
    // err is ParseError.INVALID_KEY_NAME but doesn't have an error message.
  },
});

Closes: #2104

Approach

  • Remove backbone options.error
  • Add error message for Parse.Error.INVALID_KEY_NAME
  • Improve documentation for chaining
  • set now throws validation errors

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)

Copy link

Thanks for opening this pull request!

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (fa34827) to head (e4e3929).
Report is 18 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff            @@
##             alpha     #2445   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         6256      6256           
  Branches      1452      1446    -6     
=========================================
  Hits          6256      6256           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dplewis dplewis requested a review from a team February 12, 2025 19:54
@mtrezza
Copy link
Member

mtrezza commented Feb 12, 2025

Now is a good time to merge any breaking changes. We can release with Parse Server 8.

@mtrezza mtrezza added the state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message label Feb 14, 2025
@mtrezza mtrezza changed the title fix: Remove Parse.Object.set option for validation error fix: Remove Parse.Object.set option error for validation error handling Feb 14, 2025
@mtrezza
Copy link
Member

mtrezza commented Feb 14, 2025

BREAKING CHANGE: Removes the validation error option from Parse.Object.set, Parse.Object.setACL and instead throws on validation errors. For example, instead of using Parse.Object.set(key, value, { error: ... }) wrap Parse.Object.set(key, value) into a try/catch block.

@dplewis Is this proposed changelog entry correct?

@mtrezza mtrezza changed the title fix: Remove Parse.Object.set option error for validation error handling fix: Remove Parse.Object.set and Parse.Object.setACL option error for validation error handling Feb 14, 2025
@dplewis
Copy link
Member Author

dplewis commented Feb 14, 2025

There is also Parse.Object.unset and Parse.Role.setName that throw errors now.

Edit: Basically setting / updating a field with invalid key or acl will throw error now. Before you would have to save first to get the error. If a developer fixed all errors before updating to using this change there shouldn't be any issues. If they just set fields and never saved then that would be a breaking change

@mtrezza
Copy link
Member

mtrezza commented Feb 14, 2025

I guess these are 2 changes then:

  1. remove error option
  2. throw not at save but at set et al.

Could we do only (1) and not (2), if it's not necessary for (1)? In any case, if the primary purpose of this PR is (1), then this would be a breaking change either way, because it's possible that someone is using it, right?

@dplewis
Copy link
Member Author

dplewis commented Feb 15, 2025

remove error option

If you didn't pass an error option the error would be slienced but now it's thrown

throw not at save but at set et al.

The error would get thrown before you get a chance to save.

@mtrezza
Copy link
Member

mtrezza commented Feb 15, 2025

So the original behavior is:

  • if error option is set, then error is thrown at .set
  • if error option is not set, then error is thrown at .save

New behavior with this PR:

  • error is thrown at .set (error option doesn't exist anymore)

Is that correct?

@dplewis
Copy link
Member Author

dplewis commented Feb 15, 2025

This is correct. Users have reported that save didn’t throw at all like #1386 and there were a few other examples but I can't find them.

@mtrezza
Copy link
Member

mtrezza commented Feb 15, 2025

Do you think it makes more sense to throw on .set or on .save? Throwing on .save seems to make more sense to me, because .set seems more like a non-op. Do we have any other similar examples in the SDK?

@dplewis
Copy link
Member Author

dplewis commented Feb 15, 2025

I think it should throw on .set because it's easier to debug where the error is in the stack trace. Also this PR adds a message for INVALID_KEY_NAME error so you can get the name of the key. The documentation and return types are improved and consistent with the rest of the SDK like query chaining. .set returning Parse.Object | boolean is weird.

@dplewis dplewis closed this Feb 15, 2025
@dplewis dplewis deleted the set-validation branch February 15, 2025 23:48
@dplewis dplewis restored the set-validation branch February 15, 2025 23:50
@dplewis dplewis reopened this Feb 15, 2025
@mtrezza
Copy link
Member

mtrezza commented Feb 16, 2025

BREAKING CHANGE: Removes the error handler option error from Parse.Object.set, Parse.Object.setACL, Parse.Object.unset, Parse.Role.setName and instead throws on validation error. Previously, if the error option was set, the handler was invoked if a validation error occurred on Parse.Object.set, and if no handler was set, an error was thrown on Parse.Object.save. The new behavior is that an error is thrown at Parse.Object.set. For example, instead of using Parse.Object.set(key, value, { error: ... }) wrap Parse.Object.set(key, value) into a try/catch block.

@dplewis Is this proposed changelog entry correct?

@dplewis
Copy link
Member Author

dplewis commented Feb 16, 2025

LGTM!

@mtrezza mtrezza changed the title fix: Remove Parse.Object.set and Parse.Object.setACL option error for validation error handling fix: Remove validation handler option error from various methods of Parse.Object Feb 16, 2025
@mtrezza mtrezza changed the title fix: Remove validation handler option error from various methods of Parse.Object fix: Remove validation error handler option error from various methods of Parse.Object Feb 16, 2025
@mtrezza mtrezza merged commit 52ddaee into parse-community:alpha Feb 16, 2025
22 checks passed
parseplatformorg pushed a commit that referenced this pull request Feb 16, 2025
# [6.0.0-alpha.1](5.3.0-alpha.6...6.0.0-alpha.1) (2025-02-16)

### Bug Fixes

* Remove validation error handler option `error` from various methods of `Parse.Object` ([#2445](#2445)) ([52ddaee](52ddaee))

### BREAKING CHANGES

* Removes the error handler option `error` from `Parse.Object.set`, `Parse.Object.setACL`, `Parse.Object.unset`, `Parse.Role.setName` and instead throws on validation error. Previously, if the `error` option was set, the handler was invoked if a validation error occurred on `Parse.Object.set`, and if no handler was set, an error was thrown on `Parse.Object.save`. The new behavior is that an error is thrown at `Parse.Object.set`. For example, instead of using `Parse.Object.set(key, value, { error: ... })` wrap `Parse.Object.set(key, value)` into a `try/catch` block. ([52ddaee](52ddaee))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.0.0-alpha.1

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Feb 16, 2025
parseplatformorg pushed a commit that referenced this pull request Mar 2, 2025
# [6.0.0](5.3.0...6.0.0) (2025-03-02)

### Bug Fixes

* `Parse.Hooks` requests have double forward slash in URL ([#2441](#2441)) ([1fc520c](1fc520c))
* `Parse.Query.findAll` not returning all objects with option `json: true` ([#2449](#2449)) ([f160b8c](f160b8c))
* Cannot pass `useMasterKey: false` to `Parse.Cloud.run` ([#2431](#2431)) ([abadac9](abadac9))
* Remove validation error handler option `error` from various methods of `Parse.Object` ([#2445](#2445)) ([52ddaee](52ddaee))
* Security upgrade dset from 3.1.3 to 3.1.4 ([#2277](#2277)) ([058f8e4](058f8e4))

### Features

* Add transaction to save and destroy on `Parse.Object` ([#2265](#2265)) ([2b55bdf](2b55bdf))

### BREAKING CHANGES

* Internal REST requests for `Parse.Hooks` use a URL that contains a double forward slash, for example `http://localhost/parse//hooks/functions`. This release changes the double forward slash to a single forward slash. ([1fc520c](1fc520c))
* Removes the error handler option `error` from `Parse.Object.set`, `Parse.Object.setACL`, `Parse.Object.unset`, `Parse.Role.setName` and instead throws on validation error. Previously, if the `error` option was set, the handler was invoked if a validation error occurred on `Parse.Object.set`, and if no handler was set, an error was thrown on `Parse.Object.save`. The new behavior is that an error is thrown at `Parse.Object.set`. For example, instead of using `Parse.Object.set(key, value, { error: ... })` wrap `Parse.Object.set(key, value)` into a `try/catch` block. ([52ddaee](52ddaee))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message state:released Released as stable version state:released-alpha Released as alpha version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse.Object.set sliently handles validation errors
3 participants