diff --git a/python/ray/dashboard/client/src/util/converter.ts b/python/ray/dashboard/client/src/util/converter.ts index 0bfd52736de6..54d926b96688 100644 --- a/python/ray/dashboard/client/src/util/converter.ts +++ b/python/ray/dashboard/client/src/util/converter.ts @@ -1,4 +1,8 @@ -export const memoryConverter = (bytes: number) => { +export const memoryConverter = (bytes: number | undefined | null) => { + if (typeof bytes !== "number" || Number.isNaN(bytes)) { + return "-"; + } + if (bytes < 1024) { return `${bytes.toFixed(4)}B`; } diff --git a/python/ray/dashboard/client/src/util/converter.unit.test.ts b/python/ray/dashboard/client/src/util/converter.unit.test.ts index a3d544c78d60..7adef830751c 100644 --- a/python/ray/dashboard/client/src/util/converter.unit.test.ts +++ b/python/ray/dashboard/client/src/util/converter.unit.test.ts @@ -37,4 +37,18 @@ describe("memoryConverter", () => { test.each(table)("$name", ({ input, expected }) => { expect(memoryConverter(input)).toEqual(expected); }); + + describe("edge cases", () => { + test("returns '-' for null", () => { + expect(memoryConverter(null)).toEqual("-"); + }); + + test("returns '-' for undefined", () => { + expect(memoryConverter(undefined)).toEqual("-"); + }); + + test("returns '-' for NaN", () => { + expect(memoryConverter(NaN)).toEqual("-"); + }); + }); });