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

  1. Strip non-numeric characters and normalize the decimal separator before assignment: parseFloat(String(v).replace(/[^0-9.-]/g, '')).
  2. Treat empty strings as null instead of passing them to the field.
  3. Validate payloads at the API boundary with a numeric schema check (Number.isFinite).
  4. 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

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


AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01). Data as JSON: /api/errors/35a2e04f3233d5f5. Report an issue: GitHub.