fix(catalog): normalize missing product prices - #2322
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 product responses to treat missing
pricesas empty arrays. Prevents catalog analysis from crashing on historical products and keeps theupdateableflag safe.pricesto[]when mapping items ingetPlanResponseandgetProductResponse.updateablewith(product.prices ?? []).some(...)to avoid undefined access.Written for commit ad32b7c. Summary will update on new commits.
Greptile Summary
This PR adds
?? []null-coalescing guards at three call sites whereproduct.pricesis passed intomapToProductItemsor iterated, preventing crashes when historical products have missing price arrays. The fix is applied consistently to bothgetPlanResponse.tsandgetProductResponse.ts.getPlanResponse.ts: guardsproduct.pricesbeforemapToProductItems, preventing a runtime crash for historical products with no price data.getProductResponse.ts: guardsproduct.pricesin themapToProductItemscall and theupdateable.some()check; however, the same null/undefinedproduct.priceswill still crash whengetProductPropertiescallsproductToEffectivePrices({ product }), which spreadsproduct.pricesdirectly without a guard.Confidence Score: 3/5
The fix is incomplete —
getProductResponsestill has an unguarded spread ofproduct.pricesinsideproductToEffectivePrices, which will throw for the same historical products this PR intends to protect.Two of the three guarded call sites are correct, but
getProductPropertiescallsproductToEffectivePrices({ product }), which spreadsproduct.pricesdirectly. A historical product with null prices will still crash atis_free/is_one_offcomputation ingetProductResponse, making the catalog analysis fix only partially effective.server/src/internal/products/productUtils/productResponseUtils/getProductResponse.ts — the
getProductPropertiesfunction and its downstream call toproductToEffectivePricesneed the same null guard treatment.Important Files Changed
?? []null guard toproduct.pricesbefore passing tomapToProductItems; the change is minimal and correct for this file.?? []guards to themapToProductItemscall and theupdateable.some()check, butgetProductPropertiesstill callsproductToEffectivePrices({ product })which spreadsproduct.priceswithout a null guard — the same crash scenario is still reachable viais_free/is_one_offcomputation.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[getProductResponse / getPlanResponse] --> B["mapToProductItems\n(product.prices ?? [] ✅ fixed)"] A --> C[getProductProperties] C --> D["updateable: (product.prices ?? []).some(...)\n✅ fixed"] C --> E["productToEffectivePrices({ product })\n...product.prices ❌ still unguarded"] E --> F["isFreeProduct / isOneOffProduct / getLargestInterval"] E --> G["TypeError if product.prices is null"]%%{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[getProductResponse / getPlanResponse] --> B["mapToProductItems\n(product.prices ?? [] ✅ fixed)"] A --> C[getProductProperties] C --> D["updateable: (product.prices ?? []).some(...)\n✅ fixed"] C --> E["productToEffectivePrices({ product })\n...product.prices ❌ still unguarded"] E --> F["isFreeProduct / isOneOffProduct / getLargestInterval"] E --> G["TypeError if product.prices is null"]Comments Outside Diff (1)
server/src/internal/products/productUtils/productResponseUtils/getProductResponse.ts, line 141-158 (link)productToEffectivePricesstill spreadsproduct.priceswithout a null guardgetProductPropertiescallsproductToEffectivePrices({ product })on line 141, which does[...product.prices, ...](spread ofproduct.prices). For the same historical products this PR targets — whereproduct.pricescan be null/undefined — this will still throw a TypeError ("null is not iterable") before theis_free,is_one_off,interval_group, andhas_trialproperties can be computed. The three?? []guards added here and ingetPlanResponse.tsdo not cover this code path;productToEffectivePricesitself would need the same normalization.Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(catalog): normalize missing product ..." | Re-trigger Greptile