Skip to content

Fix billing null guards#3054

Open
HarshMN2345 wants to merge 2 commits into
mainfrom
fix-billing-null-guards
Open

Fix billing null guards#3054
HarshMN2345 wants to merge 2 commits into
mainfrom
fix-billing-null-guards

Conversation

@HarshMN2345
Copy link
Copy Markdown
Member

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 20, 2026

Greptile Summary

This PR adds defensive null/optional-chaining guards across four files to prevent TypeError crashes when billing plan data or user account data is not yet populated. No behavioural changes are introduced — each fix is a minimal, targeted safeguard.

  • billing.ts: billingIdToPlan now accepts null | undefined and returns early; checkForUsageFees and checkForProjectLimitation propagate that via optional chaining; checkForNewDevUpgradePro gains guards on both billingPlanDetails and account.$createdAt.
  • tab.svelte: handleKeyDown gains three early-returns guarding against closest() returning null and indexOf returning -1.
  • containerHeader.svelte / newDevUpgradePro.svelte: Optional chaining added on $currentPlan?.usage and billingPlanDetails?.supportsCredits respectively.

Confidence Score: 5/5

All changes are additive null guards with no logic alterations — safe to merge.

Every change is a narrow defensive fix: optional chaining, nullish coalescing, or an early return. The previously flagged unguarded access in checkForProjectLimitation (billingPlan.projects) has been addressed with billingPlan?.projects. No new code paths are introduced and all fallback values are conservative.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/stores/billing.ts Adds null/undefined guards across billingIdToPlan, checkForUsageFees, checkForProjectLimitation, and checkForNewDevUpgradePro — all previously raised runtime errors are addressed
src/lib/components/tab.svelte Adds three defensive early-returns in handleKeyDown for null tabItem, null tabsList, and indexOf returning -1 — correct and safe
src/lib/layout/containerHeader.svelte Guards Object.keys access on $currentPlan?.usage with nullish coalescing fallback to empty object
src/lib/components/billing/alerts/newDevUpgradePro.svelte Adds optional chaining on billingPlanDetails?.supportsCredits in the template condition

Reviews (2): Last reviewed commit: "Guard project limitation plan lookup" | Re-trigger Greptile

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.

1 participant