Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 088e9897a6 fix: handle unrecognized operands in DATE/DATE_TIME filter gracefully
https://sonarly.com/issue/33840?type=bug

The DATE filter type in `turnRecordFilterIntoGqlOperationFilter` throws an unhandled error when encountering an `IS_NOT` operand, crashing the entire record table view for any object with such a persisted filter.

Fix: Changed the `throw new Error(...)` fallthrough in both the `DATE` and `DATE_TIME` switch cases of `turnRecordFilterIntoRecordGqlOperationFilter` to `return;` (returning `undefined`).

This is the exact same fix pattern applied in two prior commits for the same class of bug:
- TEXT filter with stale `IS` operand (commit aba5c93a6f)
- RELATION filter with invalid `EQUAL_TO` operand (commit 3c0627958d)

The function's return type is `RecordGqlOperationFilter | undefined`, and all callers in `computeRecordGqlOperationFilter` and `turnRecordFilterGroupsIntoGqlOperationFilter` already filter results with `.filter(isDefined)`. Returning `undefined` gracefully skips the unrecognized operand instead of crashing the entire page.

Added two test cases verifying that `IS_NOT` on DATE and DATE_TIME fields returns `undefined` instead of throwing.
2026-05-04 07:25:53 +00:00
2 changed files with 30 additions and 6 deletions
@@ -342,6 +342,20 @@ describe('turnRecordFilterIntoRecordGqlOperationFilter', () => {
expect(result).toHaveProperty('and');
});
it('should return undefined for unsupported operand like IS_NOT', () => {
const result = turnRecordFilterIntoRecordGqlOperationFilter({
filterValueDependencies,
recordFilter: makeFilter(
'f-date',
RecordFilterOperand.IS_NOT,
'2024-03-15',
),
fieldMetadataItems: fields,
});
expect(result).toBeUndefined();
});
});
describe('DATE_TIME filter', () => {
@@ -442,6 +456,20 @@ describe('turnRecordFilterIntoRecordGqlOperationFilter', () => {
expect(result).toHaveProperty('and');
});
it('should return undefined for unsupported operand like IS_NOT', () => {
const result = turnRecordFilterIntoRecordGqlOperationFilter({
filterValueDependencies,
recordFilter: makeFilter(
'f-datetime',
RecordFilterOperand.IS_NOT,
'2024-03-15T10:00:00Z',
),
fieldMetadataItems: fields,
});
expect(result).toBeUndefined();
});
});
describe('RATING filter', () => {
@@ -288,9 +288,7 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
}
}
throw new Error(
`Unknown operand ${recordFilter.operand} for ${filterType} filter`,
);
return;
}
case 'DATE_TIME': {
const itsARelativeDateTimeFilter =
@@ -446,9 +444,7 @@ export const turnRecordFilterIntoRecordGqlOperationFilter = ({
}
}
throw new Error(
`Unknown operand ${recordFilter.operand} for ${filterType} filter`,
);
return;
}
case 'RATING':
switch (recordFilter.operand) {