Skip to content

fix: add runtime type guard for cpu.value in monitoring tab#4189

Merged
Siumauricio merged 1 commit intocanaryfrom
fix/monitoring-cpu-value-type-guard
Apr 9, 2026
Merged

fix: add runtime type guard for cpu.value in monitoring tab#4189
Siumauricio merged 1 commit intocanaryfrom
fix/monitoring-cpu-value-type-guard

Conversation

@Siumauricio
Copy link
Copy Markdown
Contributor

@Siumauricio Siumauricio commented Apr 9, 2026

Summary

  • Fixes the c.cpu.value.replace is not a function crash on the monitoring tab when cpu.value is a number or null instead of a string
  • Adds String() conversion with "0%" fallback, matching the defensive approach already used for memory values

Closes #4062

Greptile Summary

This PR adds defensive runtime guards for cpu.value in the free container monitoring tab, wrapping it with String(value ?? "0%") to prevent crashes when the WebSocket or API response delivers a number or null instead of the expected string. The fix is minimal and consistent with the defensive pattern already used for memory values in the same component.

Confidence Score: 5/5

Safe to merge — the crash is fixed with a targeted, consistent guard and no regressions are introduced.

The only remaining finding is a P2 type-annotation improvement that doesn't affect runtime behaviour. All P0/P1 concerns are addressed.

No files require special attention.

Comments Outside Diff (1)

  1. apps/dokploy/components/dashboard/monitoring/free/container/show-free-container-monitoring.tsx, line 49-52 (link)

    P2 TypeScript type doesn't reflect runtime reality

    The DockerStats interface still declares cpu.value as string, but this PR exists precisely because it can arrive as number | null at runtime. The ?? "0%" guard is then effectively invisible to TypeScript — the compiler won't warn about future callers that use .replace() without the guard. Consider updating the type to match what the data source can actually produce:

    cpu: {
      value: string | number | null;
      time: string;
    };

Reviews (1): Last reviewed commit: "fix: add runtime type guard for cpu.valu..." | Re-trigger Greptile

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 9, 2026
@Siumauricio Siumauricio merged commit a30617d into canary Apr 9, 2026
5 checks passed
@Siumauricio Siumauricio deleted the fix/monitoring-cpu-value-type-guard branch April 9, 2026 23:25
@dosubot dosubot bot added the bug Something isn't working label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

400 Error monitoring tab some services

1 participant