-
-
Notifications
You must be signed in to change notification settings - Fork 600
Fix: sets default value for missing options parameter #2771
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: sets default value for missing options parameter #2771
Conversation
Signed-off-by: Manuel <[email protected]>
Signed-off-by: Manuel <[email protected]>
Ensures that the `options` argument in the `run` function is initialized to an empty object if it is undefined, preventing potential errors when accessing properties of `options` later in the function. Signed-off-by: Marcus Olsson <[email protected]>
|
🚀 Thanks for opening this pull request! |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
📝 WalkthroughWalkthroughFixes null handling in the Cloud.run options parameter by setting a default empty object when options is null or undefined, preventing downstream errors when null is passed instead of undefined. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Signed-off-by: Marcus Olsson <[email protected]>
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Cloud.ts (1)
126-126: Critical: Null-safety issue in startJob method.Line 126 directly assigns
options.returnStatus = truewithout checking ifoptionsis defined. IfstartJobis called without options (or with null), this will throw a TypeError, similar to the issue this PR fixes in therunmethod.Add null-safety before accessing options:
async startJob(name: string, data: any, options?: RequestOptions): Promise<string> { const RESTController = CoreManager.getRESTController(); const payload = encode(data, true); + options = options ?? {}; options.returnStatus = true; const response = await RESTController.request('POST', 'jobs/' + name, payload, options); return response._headers?.['X-Parse-Job-Status-Id']; },
🧹 Nitpick comments (1)
src/Cloud.ts (1)
49-49: Good fix; consider using nullish coalescing for precision.The fix correctly addresses the reported TypeError when null is passed. However,
||converts all falsy values (0, false, "", etc.) to{}, whereas nullish coalescing (??) only defaults null/undefined. Given the TypeScript signature, both work, but??is more precise and aligns with modern best practices.Apply this diff to use nullish coalescing:
- options = options || {}; + options = options ?? {};
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Cloud.ts(1 hunks)
🔇 Additional comments (1)
src/Cloud.ts (1)
48-54: Verify test coverage for null options handling.The PR objectives indicate that tests have not yet been added. Please ensure unit tests cover the scenario where
nullis explicitly passed as the options parameter to verify the fix works as expected.Example test case to add:
// Test that null options doesn't throw TypeError await Parse.Cloud.run('functionName', { data: 'value' }, null);
Pull Request
This Pull Request fixes a line of code that existed in
Cloud.tsin v5.3.0 but was removed in v6.0.0.This removal added a breaking change of the code with different behaviour when the options parameter is null.
Relates to #2622 and #2623
Issue
Closes: #2622
Approach
Tasks
Summary by CodeRabbit