Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code f1371577cf fix: handle non-numeric input gracefully in SettingsCounter
https://sonarly.com/issue/16514?type=bug

When users type non-numeric characters into the SettingsCounter text input (e.g., on the new field configuration page), `castAsNumberOrNull` throws an unhandled "Cannot cast to number or null" error that crashes the React tree.

Fix: Added `canBeCastAsNumberOrNull` guard before calling `castAsNumberOrNull` in `SettingsCounter.handleTextInputChange`, following the same pattern used by all other callers in the codebase (`NumberFieldInput`, `CommandMenuItemNumberInput`, `FormNumberFieldInput`).

When a user types non-numeric characters into the counter text input, the function now returns early (ignoring the invalid input) instead of letting `castAsNumberOrNull` throw an unhandled error that crashes the React tree. The counter retains its previous valid value until valid numeric input is entered.

**Changes:**
- Import `canBeCastAsNumberOrNull` alongside existing `castAsNumberOrNull` import
- Add guard check `if (!canBeCastAsNumberOrNull(value)) return;` before the `castAsNumberOrNull` call
2026-03-19 13:59:18 +00:00
@@ -3,7 +3,10 @@ import { styled } from '@linaria/react';
import { IconMinus, IconPlus } from 'twenty-ui/display';
import { IconButton } from 'twenty-ui/input';
import { themeCssVariables } from 'twenty-ui/theme-constants';
import { castAsNumberOrNull } from '~/utils/cast-as-number-or-null';
import {
canBeCastAsNumberOrNull,
castAsNumberOrNull,
} from '~/utils/cast-as-number-or-null';
type SettingsCounterProps = {
value: number;
@@ -57,6 +60,10 @@ export const SettingsCounter = ({
};
const handleTextInputChange = (value: string) => {
if (!canBeCastAsNumberOrNull(value)) {
return;
}
const castedNumber = castAsNumberOrNull(value);
if (castedNumber === null) {
onChange(minValue);