Skip to content

Commit e1725f9

Browse files
committed
formatBytes protection from divide by zero
1 parent 2d002f9 commit e1725f9

File tree

1 file changed

+4
-1
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query

1 file changed

+4
-1
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export function formatBytes(bytes: number): string {
2424
if (bytes < 0) return "-" + formatBytes(-bytes);
2525
const k = 1024;
2626
const sizes = ["B", "KB", "MB", "GB"];
27-
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
27+
const i = Math.max(
28+
0,
29+
Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1)
30+
);
2831
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
2932
}
3033

0 commit comments

Comments
 (0)