fix: Server crash from unhandled promise rejection when multiple Cloud Code validator fields fail#10540
Conversation
…d Code validator fields fail
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
📝 WalkthroughWalkthroughFixes a server crash caused by an unhandled promise rejection when multiple Cloud Code validated fields fail simultaneously. Refactors field validation in ChangesValidation rejection fix
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant CloudFunction
participant builtInTriggerValidator
participant validateOptions
CloudFunction->>builtInTriggerValidator: invoke with multiple invalid fields
loop for each field in options.fields
builtInTriggerValidator->>builtInTriggerValidator: collect [opt, key, val] into optionValidations
end
builtInTriggerValidator->>validateOptions: Promise.all(optionValidations.map(validateOptions))
validateOptions-->>builtInTriggerValidator: rejection reasons
builtInTriggerValidator-->>CloudFunction: reject with VALIDATION_ERROR (no unhandled rejection)
🚥 Pre-merge checks | ✅ 5 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. 🔧 Biome (2.5.1)src/triggers.jsFile contains syntax errors that prevent linting: Line 230: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 230: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 230: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 230: return types can only be used in TypeScript files Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/triggers.js (1)
903-912: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winSame latent pattern remains in the
requireUserKeysbranch.This block still invokes
validateOptions(...)immediately inside the loop beforePromise.all, the same pattern that caused#8826in theoptions.fieldsbranch. It's not currently exploitable here since no other statement in this loop throws synchronously, but it's structurally fragile — any future addition of a synchronous check (e.g. arequiredvalidation) in this loop would reintroduce the same unhandled-rejection risk. Consider applying the same input-deferral pattern here for consistency.♻️ Suggested consistency fix
} else if (typeof userKeys === 'object') { - const optionPromises = []; + const optionValidations = []; for (const key in options.requireUserKeys) { const opt = options.requireUserKeys[key]; if (opt.options) { - optionPromises.push(validateOptions(opt, key, reqUser.get(key))); + optionValidations.push([opt, key, reqUser.get(key)]); } } - await Promise.all(optionPromises); + await Promise.all(optionValidations.map(([o, k, v]) => validateOptions(o, k, v))); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/triggers.js` around lines 903 - 912, The `requireUserKeys` branch in `src/triggers.js` has the same eager-promise pattern as the earlier `options.fields` fix: `validateOptions(...)` is being invoked directly inside the loop before `Promise.all`, which can reintroduce unhandled-rejection risk if a future synchronous check is added. Update the logic in this branch to defer execution the same way as the `options.fields` path, collecting functions/thunks (or equivalent deferred work) and only invoking `validateOptions` during the `Promise.all` phase, keeping `userKeys` handling consistent and safe.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/triggers.js`:
- Around line 903-912: The `requireUserKeys` branch in `src/triggers.js` has the
same eager-promise pattern as the earlier `options.fields` fix:
`validateOptions(...)` is being invoked directly inside the loop before
`Promise.all`, which can reintroduce unhandled-rejection risk if a future
synchronous check is added. Update the logic in this branch to defer execution
the same way as the `options.fields` path, collecting functions/thunks (or
equivalent deferred work) and only invoking `validateOptions` during the
`Promise.all` phase, keeping `userKeys` handling consistent and safe.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4d4e34ea-7b2f-4ebd-a9aa-6101770f1c21
📒 Files selected for processing (2)
spec/CloudCode.Validator.spec.jssrc/triggers.js
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #10540 +/- ##
=======================================
Coverage 92.66% 92.66%
=======================================
Files 193 193
Lines 16981 16981
Branches 248 248
=======================================
Hits 15736 15736
Misses 1224 1224
Partials 21 21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #8826
Summary by CodeRabbit