Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion python/ray/dashboard/client/src/util/converter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export const memoryConverter = (bytes: number) => {
export const memoryConverter = (bytes: number | undefined | null) => {
// The reporter agent serializes psutil process stats via as_dict(), which
// yields null for fields psutil cannot read (e.g. pfaults/pageins on some
// platforms, or when AccessDenied is raised). Guard against null/undefined
// /NaN so the Worker table keeps rendering instead of crashing on `.toFixed`.
if (typeof bytes !== "number" || Number.isNaN(bytes)) {
return "-";
}

if (bytes < 1024) {
return `${bytes.toFixed(4)}B`;
}
Expand Down
20 changes: 20 additions & 0 deletions python/ray/dashboard/client/src/util/converter.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,24 @@ describe("memoryConverter", () => {
test.each(table)("$name", ({ input, expected }) => {
expect(memoryConverter(input)).toEqual(expected);
});

// The reporter agent serializes psutil process stats with as_dict(), which
// emits null for fields that psutil cannot read (e.g. pfaults/pageins on
// some platforms or when AccessDenied is raised). memoryConverter must not
// crash on null/undefined/NaN, otherwise the Worker table fails to render.
// See: https://github.com/ray-project/ray/issues (Cannot read properties of
// null (reading 'toFixed') at converter.ts)
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("-");
});
});
});
Loading