Skip to content

fix: tolerate null allocation sets in allocation views - #292

Open
markusheiden wants to merge 1 commit into
opencost:mainfrom
markusheiden:null-fix
Open

fix: tolerate null allocation sets in allocation views#292
markusheiden wants to merge 1 commit into
opencost:mainfrom
markusheiden:null-fix

Conversation

@markusheiden

Copy link
Copy Markdown

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:

{"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.

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.

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>
@netlify

netlify Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploy Preview for opencost-ui ready!

Name Link
🔨 Latest commit dd18ae4
🔍 Latest deploy log https://app.netlify.com/projects/opencost-ui/deploys/6a7ed87290347c00080599e8
😎 Deploy Preview https://deploy-preview-292--opencost-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant