Skip to content

Commit a0b5d68

Browse files
authored
more defensive coding around dayjs (#18723)
1 parent c335960 commit a0b5d68

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

web-console/src/utils/date.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,9 @@ export function formatDate(value: string) {
106106
LocalStorageKeys.WEB_CONSOLE_CONFIGS,
107107
);
108108
const showLocalTime = webConsoleConfig?.showLocalTime;
109-
return showLocalTime ? dayjs(value).format(DATE_FORMAT) : dayjs(value).toISOString();
109+
try {
110+
return showLocalTime ? dayjs(value).format(DATE_FORMAT) : dayjs(value).toISOString();
111+
} catch {
112+
return value;
113+
}
110114
}

web-console/src/views/segments-view/segments-view.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,16 @@ function segmentFiltersToExpression(filters: Filter[]): SqlExpression {
168168
if (modeAndNeedle.mode === '~') {
169169
return sqlQueryCustomTableFilter(filter);
170170
}
171-
const internalFilter = { ...filter };
172-
const formattedDate = formatDate(modeAndNeedle.needle);
173-
const filterDate = dayjs(formattedDate).toISOString();
174-
filter.value = combineModeAndNeedle(modeAndNeedle.mode, formattedDate);
175-
internalFilter.value = combineModeAndNeedle(modeAndNeedle.mode, filterDate);
176-
return sqlQueryCustomTableFilter(internalFilter);
171+
try {
172+
const internalFilter = { ...filter };
173+
const formattedDate = formatDate(modeAndNeedle.needle);
174+
const filterDate = dayjs(formattedDate).toISOString();
175+
filter.value = combineModeAndNeedle(modeAndNeedle.mode, formattedDate);
176+
internalFilter.value = combineModeAndNeedle(modeAndNeedle.mode, filterDate);
177+
return sqlQueryCustomTableFilter(internalFilter);
178+
} catch {
179+
return sqlQueryCustomTableFilter(filter);
180+
}
177181
}
178182
if (filter.id === 'shard_type') {
179183
// Special handling for shard_type that needs to be searched for in the shard_spec
@@ -743,8 +747,13 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment
743747
show: visibleColumns.shown('Time span'),
744748
id: 'time_span',
745749
className: 'padded',
746-
accessor: ({ start, end }) =>
747-
computeSegmentTimeSpan(dayjs(start).toISOString(), dayjs(end).toISOString()),
750+
accessor: ({ start, end }) => {
751+
try {
752+
return computeSegmentTimeSpan(dayjs(start).toISOString(), dayjs(end).toISOString());
753+
} catch {
754+
return 'Invalid start or end';
755+
}
756+
},
748757
width: 100,
749758
sortable: false,
750759
filterable: false,

0 commit comments

Comments
 (0)