nocodb/nocodb · error · FormulaError
INVALID_ARG
INVALID_ARG
Error message
The REPEAT function requires a numeric as the parameter at position 2
What it means
Thrown by the REPEAT custom validator (formulas.ts:505) when the resolved type of the second argument (the repeat count) is not FormulaDataTypes.NUMERIC. Unlike the date checks this one inspects argTypes (the post-recursion resolved types), so it applies to BOTH literals and column references. REPEAT's declared args has no generic type, so the custom validator is the sole type gate.
Source
Thrown at packages/nocodb-sdk/src/lib/formula/formulas.ts:505
type: FormulaDataTypes.NUMERIC,
},
},
description:
'Calculate the remainder resulting from integer division of input parameters.',
syntax: 'MOD(value1, value2)',
examples: ['MOD(1024, 1000) => 24', 'MOD({column}, 2)'],
returnType: FormulaDataTypes.NUMERIC,
},
REPEAT: {
docsUrl: `${API_DOC_PREFIX}/field-types/formula/string-functions#repeat`,
validation: {
args: {
rqd: 2,
},
custom(argTypes: FormulaDataTypes[], parsedTree) {
if (argTypes[1] !== FormulaDataTypes.NUMERIC) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.typeIsExpected',
type: 'Numeric',
calleeName: parsedTree.callee?.name?.toUpperCase(),
position: 2,
},
'The REPEAT function requires a numeric as the parameter at position 2'
);
}
},
},
description:
'Concatenate the specified number of copies of the input parameter string.',
syntax: 'REPEAT(str, count)',
examples: ['REPEAT("A", 5) => "AAAAA"', 'REPEAT({column}, 5)'],
returnType: FormulaDataTypes.STRING,
},View on GitHub (pinned to d3caaf4e89)
Solutions
- Pass a numeric literal unquoted: REPEAT({Name}, 5).
- Point the second argument at a Number column: REPEAT({Name}, {Count}).
- If the value comes from a string column, wrap or convert it to a numeric expression first.
Example fix
// before
REPEAT({Name}, "5")
// after
REPEAT({Name}, 5) Defensive patterns
Strategy: validation
Validate before calling
// Before submitting, ensure the REPEAT count arg resolves to numeric.
// If it is a literal, it must be a bare number.
function assertRepeatCountNumeric(formula: string, numericColumnTitles: Set<string>) {
const m = formula.match(/REPEAT\([^,]+,\s*(\{([^}]+)\}|['"]?[^)]*?['"]?)\s*\)/i);
if (!m) return;
const tok = m[1].trim();
if (tok.startsWith('{')) {
if (!numericColumnTitles.has(m[2])) throw new Error('REPEAT count column is not numeric');
} else if (!/^\d+(\.\d+)?$/.test(tok.replace(/^['"]|['"]$/g, ''))) {
throw new Error('REPEAT count must be a numeric literal (unquoted)');
}
} Type guard
function isRepeatNumericError(e: unknown): e is FormulaError {
return e instanceof FormulaError && e.type === FormulaErrorType.INVALID_ARG
&& e.extra?.key === 'msg.formula.typeIsExpected' && e.extra?.position === 2
&& e.extra?.calleeName === 'REPEAT';
} Try / catch
try {
await validateFormulaAndExtractTreeWithType({ formula, columns, clientOrSqlUi, getMeta });
} catch (e) {
if (e instanceof FormulaError && e.type === FormulaErrorType.INVALID_ARG
&& e.extra?.calleeName === 'REPEAT') {
// prompt: the repeat count must be numeric
}
throw e;
} Prevention
- Never quote the REPEAT count; pass a bare number or a Number column.
- Confirm the referenced count column is a Number type, not Text.
- Validate in the editor before save.
When it happens
Trigger: REPEAT("abc", "5") where the count is a quoted string literal; REPEAT({Name}, {Label}) where {Label} is a text column; REPEAT({Name}, {Flag}) with a boolean column.
Common situations: Quoting the count because it came from a form input; pointing the second arg at a text or single-select column instead of a number; leftover placeholder string in a generated formula.
Related errors
- TYPE_MISMATCH
- INVALID_ARG
- Paste operation is not supported on the active cell
- INVALID_SYNTAX
- CIRCULAR_REFERENCE
AI-assisted analysis of nocodb/nocodb@d3caaf4e89 (2026-08-12).
Data as JSON: /api/errors/b550430bf06faeff.
Report an issue: GitHub.