fix: tolerate null allocation sets in allocation views - #292
Conversation
The allocation API returns null (instead of an empty object) as the set
of days without allocation data, e.g. for windows reaching further back
than the metric history:
{"code":200,"data":[null]}
The allocation report, the cost allocation chart and the cost allocation
table called Object.values(set) on those sets, which throws
Cannot convert undefined or null to object
and crashes the whole view. The legacy UI handled null sets gracefully
(lodash forEach on null is a no-op), the new UI regressed on this.
Guard the remaining unguarded call sites with "set ?? {}", consistent
with the existing guard in runAllocationReport.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Markus Heiden <markus@markusheiden.de>
✅ Deploy Preview for opencost-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Independent confirmation of this fix, plus one detail that I think strengthens The serialisation depends on
Verified the guard against those two real responses. Running the The Browser-side, unpatched, for the record — the throw lands in console: Boundary tracks the null count exactly. Two snapshots three days apart as Possibly worth linking: opencost-ui#291 described this same scenario and was Filed as #295 so this PR has a bug report to be triaged against. |
What does this PR change?
The allocation API returns null (instead of an empty object) as the set of days without allocation data, e.g. for windows reaching further back than the metric history:
The allocation report, the cost allocation chart and the cost allocation table called Object.values(set) on those sets, which throws
and crashes the whole view. The legacy UI handled null sets gracefully (lodash forEach on null is a no-op), the new UI regressed on this.
Guard the remaining unguarded call sites with "set ?? {}", consistent with the existing guard in runAllocationReport.
Does this PR relate to any other PRs?
opencost/opencost#4004
How will this PR impact users?
No impact.
Does this PR address any GitHub or Zendesk issues?
No.
How was this PR tested?
No tests.
Does this PR require changes to documentation?
No.
Have you labeled this PR and its corresponding Issue as "next release" if it should be part of the next OpenCost release? If not, why not?
Don't know.
AI
This PR was created using Claude Code because I don't know Go. So I hope it meets your standards.