Skip to content

fix(model1): don't panic sorting a capacity column holding n/a or other text - #4309

Merged
uozalp merged 1 commit into
derailed:masterfrom
kevin9327:fix/capacity-sort-placeholder
Oct 20, 2026
Merged

uozalp merged 1 commit into
derailed:masterfrom
kevin9327:fix/capacity-sort-placeholder

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Problem

capacityToNumber (used to sort capacity columns) calls resource.MustParse, which panics on any value that isn't a Kubernetes quantity. #3869 handled the empty string, but other non-quantity values still crash k9s when that column is sorted:

  • A custom column with the N attribute (|N sets Capacity: true) shows n/a whenever its JSONPath finds nothing (cust_cols.go sets v = NAValue). Sorting by that column takes down k9s with
    panic: cannot parse 'n/a': quantities must match the regular expression ...
  • The same happens with <none> or text values such as 1/3 in an N column.

Fix

Use resource.ParseQuantity instead. A value that doesn't parse returns math.MaxInt64, so placeholders sort last, the same way durationToSeconds already handles <unknown>, <none> and n/a in age columns.

Tests

I added n/a, <none> and 1/3 cases to TestCapacityToNumber. Before the fix the test panics; after it, go test ./internal/model1 passes.

This PR was prepared with AI assistance. I reviewed and tested the change myself.

@uozalp uozalp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevin9327 thanks for this update

@uozalp
uozalp merged commit 31f772a into derailed:master Oct 20, 2026
3 checks passed
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.

2 participants