Compare commits

..

5 Commits

Author SHA1 Message Date
Jonas Schäfer
51f2ebbd13 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.
2022-01-10 17:32:11 +01:00
Jonas Schäfer
b4e6ee8943 Fix formatting of zero bytes
Previously, that would raise a ValueError (math domain error), because
log(0) is undefined.
2022-01-10 17:31:50 +01:00
Jonas Schäfer
aed9ad1cde Merge pull request #93 from Zash/debianbullseye
Dockerfile: Switch base image to Debian 11
2022-01-10 16:40:28 +01:00
Kim Alvefur
b545c137b1 Dockerfile: Switch base image to Debian 11 2022-01-10 16:27:38 +01:00
Matthew Wild
47642dc384 Merge pull request #108 from snikket-im/feature/multi-stage-dockerfile
Dockerfile: Split build into multiple stages
2022-01-10 14:21:57 +00:00
2 changed files with 7 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
FROM debian:buster-slim AS build
FROM debian:bullseye-slim AS build
RUN set -eu; \
export DEBIAN_FRONTEND=noninteractive ; \
@@ -22,7 +22,7 @@ RUN pip3 install -r requirements.txt; \
make;
FROM debian:buster-slim
FROM debian:bullseye-slim
ARG BUILD_SERIES=dev
ARG BUILD_ID=0

View File

@@ -53,11 +53,14 @@ def circle_name(c: typing.Any) -> str:
def format_bytes(n: float) -> str:
scale = math.floor(math.log(n, 1024))
try:
scale = max(math.floor(math.log(n, 1024)), 0)
except ValueError:
scale = 0
try:
unit = BYTE_UNIT_SCALE_MAP[scale]
factor = 1024**scale
except ValueError:
except IndexError:
unit = "TiB"
factor = 1024**4
if factor > 1: