nocobase/nocobase · error · Error
Invalid number value: "${value}"
Error message
Invalid number value: "${value}" What it means
The number interface sanitizes and parses the input, then validates the resulting numeric value; if validation fails (non-finite, NaN, out of expected numeric form), it throws with the original value embedded. This guards number fields against garbage input.
Source
Thrown at packages/core/database/src/interfaces/number-interface.ts:41
}
return value;
}
async toValue(value: any) {
if (value === null || value === undefined || typeof value === 'number') {
return value;
}
if (!value) {
return null;
}
const sanitizedValue = this.sanitizeValue(value);
const numberValue = this.parseValue(sanitizedValue);
if (!this.validate(numberValue)) {
throw new Error(`Invalid number value: "${value}"`);
}
return numberValue;
}
parseValue(value) {
return value;
}
validate(value) {
return !isNaN(value);
}
toString(value: number, ctx?: any) {
value = super.toString(value, ctx);
const step = this.options?.uiSchema?.['x-component-props']?.step;
if (value != null && !_.isUndefined(step)) {
const s = step.toString();View on GitHub (pinned to fa42722fef)
Solutions
- Strip non-numeric characters and normalize the decimal separator before assignment: parseFloat(String(v).replace(/[^0-9.-]/g, '')).
- Treat empty strings as null instead of passing them to the field.
- Validate payloads at the API boundary with a numeric schema check (Number.isFinite).
- Fix import column mapping so the value lands in the correct field type.
Example fix
// before
await repo.create({ values: { price: '$1,200.50' } });
// after
const price = parseFloat(String(raw).replace(/[^0-9.\-]/g, ''));
if (!Number.isFinite(price)) throw new Error('bad price');
await repo.create({ values: { price } }); Defensive patterns
Strategy: validation
Validate before calling
function toNumberSafe(v) {
if (v == null || v === '') return null;
const n = typeof v === 'number' ? v : parseFloat(String(v).replace(/[^0-9.\-]/g, ''));
if (!Number.isFinite(n)) throw new Error(`Not a number: ${JSON.stringify(v)}`);
return n;
} Type guard
function isNumericInput(v) {
if (typeof v === 'number') return Number.isFinite(v);
return typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v));
} Try / catch
try {
await repo.create({ values: { amount } });
} catch (e) {
if (e.message.startsWith('Invalid number value:')) {
console.warn(`Unparsable number: ${e.message}`);
} else throw e;
} Prevention
- Strip currency symbols and thousand separators before saving
- Normalize locale decimals ('1,5' → 1.5) on import
- Convert empty strings to null
- Validate number payloads with Number.isFinite at the API boundary
When it happens
Trigger: Assigning a value that after sanitizeValue/parseValue still fails validation — e.g. 'abc', '' (empty string), '1,2.3' with mixed separators, objects, or strings with stray characters to a number field via toValue.
Common situations: CSV/Excel imports where number columns contain thousand separators, currency symbols ('$1,200'), or text; locale-formatted decimals ('1,5'); form inputs submitting empty strings instead of null.
Related errors
- Invalid environment variable format: ${line}
- Environment variable name cannot be empty
- Environment variable "${key}" must have a value
- Performance testing script file not found: ${f}
- Please set TARGET_ORIGIN in environment variables or in .env
AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01).
Data as JSON: /api/errors/35a2e04f3233d5f5.
Report an issue: GitHub.