Skip to content

fix: Unhandled exception when calling Parse.Cloud.run with option value null (#2622) #2623

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

Merged
merged 7 commits into from
Jun 4, 2025

Conversation

modime
Copy link
Contributor

@modime modime commented May 24, 2025

Pull Request

This Pull Request is a fix for when passing null as a Parse.Cloud.run option

Issue

Closes: #2622
Closes: parse-community/parse-server#9766

Approach

Tasks

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

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced validation to accept only plain objects for the options parameter, preventing invalid input types.
  • Tests

    • Added tests to ensure proper handling of options, including acceptance of empty or undefined values and rejection of invalid types.

Copy link

parse-github-assistant bot commented May 24, 2025

🚀 Thanks for opening this pull request!

Copy link

coderabbitai bot commented May 24, 2025

📝 Walkthrough

"""

Walkthrough

The static method _getRequestOptions in ParseObject was updated to enforce that the options parameter must be a plain object, throwing an error otherwise. Corresponding tests were added to verify that Cloud.run handles invalid options types correctly and defaults to an empty object for undefined or empty options.

Changes

File(s) Change Summary
src/ParseObject.ts Added type check in _getRequestOptions to ensure options is a plain object, throwing on error
src/tests/Cloud-test.js Added tests for Cloud.run to verify correct handling of valid and invalid options values

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Cloud
    participant ParseObject

    Client->>Cloud: run(name, data, options)
    alt options is undefined or {}
        Cloud->>ParseObject: _getRequestOptions({})
        ParseObject-->>Cloud: {}
        Cloud-->>Client: result
    else options is null or not plain object
        Cloud->>ParseObject: _getRequestOptions(options)
        ParseObject-->>Cloud: throw Error
        Cloud-->>Client: Error thrown
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure _getRequestOptions handles null and invalid options gracefully (#2622, #9766)
Add tests to verify Cloud.run behavior with various options values (#2622, #9766)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-03T23_51_30_877Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8bb14b and 29fa2c5.

📒 Files selected for processing (1)
  • src/__tests__/Cloud-test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/Cloud-test.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented May 24, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/__tests__/ParseObject-test.js (1)

3546-3565: LGTM! Well-structured tests for the falsy options fix.

The test suite effectively covers the main falsy values (null, "", undefined) that could cause runtime errors when passed to Parse.Cloud.run. The tests are clear, concise, and directly address the issue described in the PR objectives.

Consider adding tests for other falsy values for completeness:

+  it('returns empty object when options is false', () => {
+    const requestOptions = ParseObject._getRequestOptions(false);
+    expect(requestOptions).toEqual({});
+  });
+
+  it('returns empty object when options is 0', () => {
+    const requestOptions = ParseObject._getRequestOptions(0);
+    expect(requestOptions).toEqual({});
+  });

Also consider adding a positive test case to ensure non-falsy values are handled correctly:

+  it('returns the options object when options is truthy', () => {
+    const options = { sessionToken: 'test' };
+    const requestOptions = ParseObject._getRequestOptions(options);
+    expect(requestOptions).toEqual(options);
+  });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24fa80d and 0eb66d7.

📒 Files selected for processing (2)
  • src/ParseObject.ts (1 hunks)
  • src/__tests__/ParseObject-test.js (1 hunks)
🔇 Additional comments (1)
src/ParseObject.ts (1)

517-519: LGTM! Excellent defensive programming practice.

This early return when options is falsy effectively prevents runtime errors when null, undefined, or other falsy values are explicitly passed to the method. While the default parameter = {} handles the case when the argument is not provided, it doesn't protect against explicit falsy values like null. This change ensures the method gracefully handles all falsy inputs by returning an empty requestOptions object, which aligns perfectly with the PR objective to fix issues when null is passed as an option.

coderabbitai[bot]
coderabbitai bot previously approved these changes May 24, 2025
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! The first question is, do we really want a call to silently succeed, even if the developer made a coding mistake?

  • Passing a string while an object is expected is a type violation, ergo clearly a coding mistake to which we want to alert the developer, so throwing makes sense.
  • Passing null may or may not be considered a coding mistake, but at a quick glance it seems like one to me. The allowed type for the options argument is undefined (no options set), or an object. Anything else is a developer error. A variable that holds null means that the developer deliberately assigned no value to it, without ensuring that it is assigned the value of an object before passing it to the method. Hence it's a type violation as well.

@mtrezza
Copy link
Member

mtrezza commented May 25, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

codecov bot commented May 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d2bdb27) to head (29fa2c5).
Report is 1 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff            @@
##             alpha     #2623   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        63           
  Lines         6193      6195    +2     
  Branches      1460      1473   +13     
=========================================
+ Hits          6193      6195    +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@modime
Copy link
Contributor Author

modime commented May 25, 2025

@mtrezza Thanks for the feedback. Update this MR as you see fit. My take on this was mostly a bug fix: If "no options" then return an empty bracket, i.e. handle null the same as undefined (and also return early in the code when there are no options to act on).

We found this error in Parse.Cloud.run (parse-server 7.5.2) when our tests with options set to null expects an Invalid request. error with the error code 141.

@mtrezza
Copy link
Member

mtrezza commented May 25, 2025

I believe when throwing like suggested it should return a proper error, instead of an internal server error. We'd have to see in the test. Would you want to incorporate the changes?

@modime
Copy link
Contributor Author

modime commented May 25, 2025

I believe when throwing like suggested it should return a proper error, instead of an internal server error. We'd have to see in the test. Would you want to incorporate the changes?

No, better you do it. I am unable to make changes for the next week as I am traveling and have limited access to the source code.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/__tests__/Cloud-test.js (1)

359-385: Consider adding more descriptive error message verification.

While the tests correctly verify that errors are thrown for invalid options, consider enhancing the second test to also verify the specific error message to ensure consistent error reporting.

  it('run throws with invalid options', () => {
    const values = [null, []];
    for (const value of values) {
-     expect(() => Cloud.run('myfunction', {}, value)).toThrow();
+     expect(() => Cloud.run('myfunction', {}, value)).toThrow('Invalid options type');
    }
  });

This would provide more precise validation of the error handling behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0eb66d7 and a8bb14b.

📒 Files selected for processing (2)
  • src/ParseObject.ts (1 hunks)
  • src/__tests__/Cloud-test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/ParseObject.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/__tests__/Cloud-test.js (15)
src/__tests__/RESTController-test.js (1)
  • CoreManager (7-7)
src/__tests__/Parse-test.js (1)
  • CoreManager (14-14)
src/__tests__/ParseObject-test.js (1)
  • CoreManager (146-146)
src/__tests__/ParseFile-test.js (1)
  • CoreManager (11-11)
src/__tests__/Hooks-test.js (1)
  • CoreManager (10-10)
src/__tests__/ParseACL-test.js (1)
  • CoreManager (16-16)
src/__tests__/LocalDatastore-test.js (1)
  • CoreManager (97-97)
src/__tests__/ParseConfig-test.js (1)
  • CoreManager (19-19)
src/__tests__/ParseRelation-test.js (1)
  • CoreManager (66-66)
src/__tests__/ParseOp-test.js (1)
  • CoreManager (40-40)
src/__tests__/Push-test.js (1)
  • CoreManager (20-20)
src/__tests__/SingleInstanceStateController-test.js (1)
  • CoreManager (27-27)
src/__tests__/canBeSerialized-test.js (1)
  • CoreManager (13-13)
src/__tests__/Storage-test.js (1)
  • CoreManager (6-6)
src/__tests__/unsavedChildren-test.js (1)
  • CoreManager (25-25)
🔇 Additional comments (2)
src/__tests__/Cloud-test.js (2)

360-377: Well-implemented test for valid empty options handling.

This test correctly verifies that Cloud.run accepts both undefined and {} as valid options and properly defaults them to an empty object when passed to the underlying controller.

The test setup with proper mocking and the iteration through valid values is well-structured.


379-384: Appropriate test for invalid options validation.

This test correctly verifies that Cloud.run throws errors when passed invalid option types (null and arrays). This aligns with the type safety approach mentioned in the AI summary where _getRequestOptions was updated to enforce plain object validation.

The test properly covers the edge cases that could cause runtime issues if not handled correctly.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 2, 2025
@modime
Copy link
Contributor Author

modime commented Jun 2, 2025

@mtrezza I'm now back at work and I have now updated the code as I hope you wanted. Please review. Thanks.

@dplewis
Copy link
Member

dplewis commented Jun 2, 2025

LGTM! I forgot the default option {} is only used for undefined not null as null is a value. Good find!

@mtrezza mtrezza changed the title fix: Add fix for when passing null as Parse.Cloud.run option (#2622) fix: Unhandled exception when calling Parse.Cloud.run with option value null (#2622) Jun 3, 2025
mtrezza
mtrezza previously approved these changes Jun 3, 2025
Signed-off-by: Manuel <[email protected]>
@mtrezza mtrezza dismissed stale reviews from coderabbitai[bot] and themself via 5adcb79 June 3, 2025 23:47
coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 3, 2025
Signed-off-by: Manuel <[email protected]>
@mtrezza mtrezza merged commit 2818ed9 into parse-community:alpha Jun 4, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when passing null as Parse.Cloud.run option Error when passing null as Parse.Cloud.run option
4 participants