fix: return proper type in calculateAndUpdateRequestCost early exit#915
Merged
fix: return proper type in calculateAndUpdateRequestCost early exit#915
Conversation
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.
CI Auto-Fix
Original PR: #913
Failed CI Run: Non-Main Branch CI/CD
Error Fixed
src/app/v1/_lib/proxy/response-handler.ts:3111return;to return proper object structureAnalysis
The function
calculateAndUpdateRequestCosthas a return type of:The early return at line 3111 was using a bare
return;which returnsundefined, but the function expects an object. The fix returns the same structure as other early returns in the function (lines 3058-3063, 3050-3053, 3168-3173).Verification
bun run typecheckpassesAuto-generated by Claude AI
Greptile Summary
This PR fixes a type error in
updateRequestCostFromUsagewhere a barereturn;on the "no price data found" code path returnedundefinedinstead of the expected{ costUsd, resolvedPricing, longContextPricing, longContextPricingApplied }object. All three call sites (lines 1001, 2016, 3251) immediately accesscostUpdateResult.longContextPricingApplied, so the bare return would have caused a runtimeTypeErrorwhen no pricing data was available for a model. The fix returns the same null-valued object structure used by the other early-return paths in the function.return;→ proper object return in the "missing price data" branch ofupdateRequestCostFromUsagenull/false) match the semantics of all other early exits in the functionConfidence Score: 5/5
return;with the correct object return type. It exactly matches the pattern of all other early returns in the same function. There are no logic changes, no new dependencies, and it fixes a real runtime crash path.Important Files Changed
return;that returnedundefinedinstead of the expected object, which would cause a runtime TypeError at all three call sites that immediately access.longContextPricingAppliedon the result.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[updateRequestCostFromUsage called] --> B{usage exists?} B -- No --> R1["return { costUsd: null, ... }"] B -- Yes --> C{model available?} C -- No --> R2["return { costUsd: null, ... }"] C -- Yes --> D[Resolve pricing from DB] D --> E{priceData valid?} E -- "No (BUG FIX HERE)" --> F["return { costUsd: null, ... }"] E -- Yes --> G[Calculate cost] G --> H{cost > 0?} H -- Yes --> R3["return { costUsd: cost, resolvedPricing, ... }"] H -- No --> R4["return { costUsd: null, resolvedPricing, ... }"] style F fill:#90EE90,stroke:#333,stroke-width:2pxLast reviewed commit: 35848b7