{{ message }}
Repository navigation
fix(dashboard): defensive guards prevent 'is not iterable' on partial backend responses (closes #304) - #311
Merged
cristim merged 1 commit intoMay 5, 2026
Conversation
… backend responses (closes #304) The 'Failed to load dashboard: e is not iterable' error was triggered when api.getRecommendations() resolved to a non-array value. The apiRequest() catch block returns `null as T` when response.json() fails on a 2xx response with an empty or non-JSON body; a non-array envelope shape from the backend produces the same symptom. Both land in groupRecsByCell() which iterates via `for...of`, throwing "null/X is not iterable" and replacing the dashboard with an error banner. Two layered guards added to dashboard.ts: - Array.isArray() check in loadDashboard() coerces any non-array recsResult value to [] before it reaches groupRecsByCell(). - try/catch soft-fail in renderDashboardSummary() around the groupRecsByCell/pageLevelRange computation so the savings card degrades to $0 rather than blanking the entire dashboard if the guard above is ever bypassed. Regression tests added for: (a) getRecommendations() returning null (b) getRecommendations() returning a non-array object ({recommendations:[]}) (c) summaryData missing by_service field entirely
Contributor
Member
Author
|
@coderabbitai review |
Contributor
This was referenced May 12, 2026
8 tasks done
7 tasks done
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.

Summary
getRecommendations()can resolve tonull(whenapiRequest's JSON-parse catch fires on a 2xx with empty/non-JSON body) or an unexpected object shape — both reachgroupRecsByCell()which usesfor...of, throwing"X is not iterable"and replacing the entire dashboard with an error banner.Array.isArray()guard inloadDashboard()to coerce any non-array fulfilled value to[]before it reachesgroupRecsByCell().renderDashboardSummary()around the savings-range computation so the Potential Monthly Savings card degrades to$0rather than blanking the dashboard if the guard is ever bypassed.Fault site (PR #295 — commit e4a52f9)
Regression tests added
#304: getRecommendations returning null does not throw "is not iterable"#304: getRecommendations returning a non-array object does not throw "is not iterable"#304: summaryData missing by_service field does not throwAll 24 dashboard tests pass.
Test plan
cd frontend && npm test -- --testPathPattern=dashboard— all 24 tests pass#304tests are green/recommendations— other cards still render, savings card shows$0Closes #304
Summary by CodeRabbit
Bug Fixes