Skip to content

Commit

Permalink
Fix unhandled exception thrown when invalid datetime ranges are provi…
Browse files Browse the repository at this point in the history
…ded in download status table

Thanks to @kaperoo for finding this one!
  • Loading branch information
louise-davies committed Aug 23, 2023
1 parent f4ff158 commit 0ff8da5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,19 @@ describe('Download Status Table', () => {
expect(screen.queryByText('test-file-4')).toBeNull();
expect(screen.queryByText('test-file-5')).toBeNull();

// create an invalid range
await user.type(dateFromFilterInput, '2020-02-28 00:00:00');

// should display error
expect(await screen.findAllByText('Invalid date-time range'));

// Should show all files
expect(await screen.findByText('test-file-1')).toBeInTheDocument();
expect(await screen.findByText('test-file-2')).toBeInTheDocument();
expect(await screen.findByText('test-file-3')).toBeInTheDocument();
expect(await screen.findByText('test-file-4')).toBeInTheDocument();
expect(await screen.findByText('test-file-5')).toBeInTheDocument();

cleanupDatePickerWorkaround();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,22 @@ const DownloadStatusTable: React.FC<DownloadStatusTableProps> = (
const endDateFilter = filter.endDate ? toDate(filter.endDate) : null;

if (startDateFilter && endDateFilter) {
satisfiedFilters.push(
isWithinInterval(tableDate, {
start: startDateFilter,
end: endDateFilter,
})
);
try {
satisfiedFilters.push(
isWithinInterval(tableDate, {
start: startDateFilter,
end: endDateFilter,
})
);
} catch (e) {
if (e instanceof RangeError) {
// isWithinInterval throws with RangeError if startDate > endDate
// in the date filter we tell the user this is invalid,
// so handle it there and do nothing here
} else {
throw e;
}
}

continue;
}
Expand Down

0 comments on commit 0ff8da5

Please sign in to comment.