fix(catalog): normalize missing product prices - #2323
Merged
Conversation
Contributor
|
Capy auto-review is paused for this organization because the usage-cycle auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Normalize missing product prices at catalog response boundaries so incomplete historical products cannot crash catalog analysis.
Summary by cubic
Normalize missing product prices to empty arrays in product and plan response mappers to prevent crashes when products lack price data. This stabilizes catalog analysis for historical or incomplete products.
product.pricesas[]ingetProductResponseandgetPlanResponse.updateablecheck by iterating over(product.prices ?? []).Written for commit 2d4fb04. Summary will update on new commits.
Greptile Summary
This PR adds
?? []null-coalescing guards forproduct.pricesat catalog response boundaries to prevent crashes when incomplete historical products have missing price data.getPlanResponse.ts: guardsproduct.pricesbefore passing tomapToProductItems, preventing a crash when prices are absent on historical products.getProductResponse.ts: guardsproduct.pricesfor both themapToProductItemscall and the.some(isPrepaidPrice)check, but the upstreamproductToEffectivePricescall on line 141 still spreadsproduct.pricesdirectly and is not covered by this fix.Confidence Score: 3/5
The fix is partially effective — it closes some crash paths but leaves
productToEffectivePricesingetProductResponseunguarded for the same null-prices scenario.Three of the four
product.pricesaccess sites are guarded, butproductToEffectivePrices(called insidegetProductProperties) spreadsproduct.pricesdirectly. Any incomplete historical product that reachesgetProductResponsewill still throw aTypeErrorat that spread before the guarded.some()check is ever reached.getProductResponse.ts — the
productToEffectivePricescall on line 141 needs the same null guard treatment as the other three sites.Important Files Changed
?? []guard forproduct.pricesbefore passing tomapToProductItems— safe and correct.?? []guards formapToProductItemsand.some(...), but the call toproductToEffectivePriceson line 141 spreadsproduct.pricesdirectly and remains unguarded — still crashable for null-prices products.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[FullProduct with null prices] --> B{getProductResponse} B --> C["mapToProductItems\n(product.prices ?? []) ✅"] B --> D["getProductProperties"] D --> E["productToEffectivePrices\n(...product.prices) ❌ unguarded"] D --> F["(product.prices ?? []).some(...) ✅"] B --> G["getAttachScenario"] H[FullProduct with null prices] --> I{getPlanResponse} I --> J["mapToProductItems\n(product.prices ?? []) ✅"]%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[FullProduct with null prices] --> B{getProductResponse} B --> C["mapToProductItems\n(product.prices ?? []) ✅"] B --> D["getProductProperties"] D --> E["productToEffectivePrices\n(...product.prices) ❌ unguarded"] D --> F["(product.prices ?? []).some(...) ✅"] B --> G["getAttachScenario"] H[FullProduct with null prices] --> I{getPlanResponse} I --> J["mapToProductItems\n(product.prices ?? []) ✅"]Comments Outside Diff (1)
server/src/internal/products/productUtils/productResponseUtils/getProductResponse.ts, line 141 (link)productToEffectivePricesstill spreadsproduct.pricesdirectlyThe same "incomplete historical products" this PR targets will crash here.
productToEffectivePrices(inshared/utils/productUtils/convertProduct/productToEffectivePrices.ts) is implemented as[...product.prices, ...], so ifproduct.pricesisnull/undefinedat runtime it throws aTypeError: null is not iterable. The three?? []guards added in this PR protectmapToProductItemsand.some(...)but leave this call unguarded.Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(catalog): normalize missing product ..." | Re-trigger Greptile