Skip to content

ui: fallback to Unspecified health status on unexpected enum values - #6421

Open
voidstackloop wants to merge 1 commit into
parca-dev:mainfrom
voidstackloop:fix/get-health-status-fallback
Open

voidstackloop wants to merge 1 commit into
parca-dev:mainfrom
voidstackloop:fix/get-health-status-fallback

Conversation

@voidstackloop

Copy link
Copy Markdown

Fixes #6372

What

In ui/packages/app/web/src/components/Targets/utils.ts, getHealthStatus(numericValue) converts a numeric enum into its display label via:

const label = Object.values(HealthStatus)[numericValue];

If numericValue is outside the range [0, 2] (e.g., negative, an unexpected value, or a newer protobuf enum introduced server-side):

  • label becomes undefined.
  • colorVariants[label] also returns undefined.
  • Returning { label: undefined, colorVariant: undefined } propagates downstream to the Pill component in TargetsTable.tsx, causing React component rendering errors.

Fix

Default to HealthStatus.Unspecified whenever the index does not resolve to a valid enum entry:

export const getHealthStatus = (numericValue: number): {label: HealthStatusType; colorVariant: PillVariant} => {
  const values = Object.values(HealthStatus);
  const label: HealthStatusType = values[numericValue] ?? HealthStatus.Unspecified;

  const colorVariants: Record<HealthStatusType, PillVariant> = {
    Unspecified: 'neutral',
    Good: 'success',
    Bad: 'danger',
  };
  return {label, colorVariant: colorVariants[label]};
};

Tests

Added test cases in ui/packages/app/web/src/components/Targets/utils.test.ts asserting that out-of-range (3), negative (-1), and NaN numeric values safely fall back to { label: 'Unspecified', colorVariant: 'neutral' }.

@voidstackloop
voidstackloop requested a review from a team as a code owner October 15, 2026 12:59

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: gethealthstatus crashes on out-of-range numeric values from protobuf

1 participant