Handle the correct exception when formatting extremely high amounts of bytes

Found in production. Yes really. Due to some borked LXC integration, my
snikket host reports

```
MemTotal:       9007199254740991 kB
MemFree:        9007199254690591 kB
MemAvailable:   9007199254690591 kB
```

That is more than 1024 TiB, so it tries to go further up in the scale,
which then causes a Guru Meditation because of the uncaught IndexError.
This commit is contained in:
Jonas Schäfer
2022-01-10 17:32:11 +01:00
parent b4e6ee8943
commit 51f2ebbd13

View File

@@ -60,7 +60,7 @@ def format_bytes(n: float) -> str:
try:
unit = BYTE_UNIT_SCALE_MAP[scale]
factor = 1024**scale
except ValueError:
except IndexError:
unit = "TiB"
factor = 1024**4
if factor > 1: