Browse Source

fix: formula - better error message with parameter position

pull/7463/head
Pranav C 11 months ago
parent
commit
8db6bbaa23
  1. 1
      packages/nc-gui/lang/en.json
  2. 30
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

1
packages/nc-gui/lang/en.json

@ -972,6 +972,7 @@
"hintStart": "Hint: Use {placeholder1} to reference fields, e.g: {placeholder2}. For more, please check out", "hintStart": "Hint: Use {placeholder1} to reference fields, e.g: {placeholder2}. For more, please check out",
"hintEnd": "Formulas.", "hintEnd": "Formulas.",
"noSuggestedFormulaFound": "No suggested formula found", "noSuggestedFormulaFound": "No suggested formula found",
"typeIsExpected": "{calleeName} requires a {type} at position {position}",
"numericTypeIsExpected": "Numeric type is expected", "numericTypeIsExpected": "Numeric type is expected",
"stringTypeIsExpected": "String type is expected", "stringTypeIsExpected": "String type is expected",
"operationNotAvailable": "{operation} operation not available", "operationNotAvailable": "{operation} operation not available",

30
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -722,10 +722,12 @@ export const formulas: Record<string, FormulaMeta> = {
throw new FormulaError( throw new FormulaError(
FormulaErrorType.INVALID_ARG, FormulaErrorType.INVALID_ARG,
{ {
key: 'msg.formula.numericTypeIsExpected', key: 'msg.formula.typeIsExpected',
type: 'Numeric',
calleeName: parsedTree.callee?.name?.toUpperCase(), calleeName: parsedTree.callee?.name?.toUpperCase(),
position: 2,
}, },
'Numeric type is expected' 'The REPEAT function requires a numeric as the parameter at position 2'
); );
} }
}, },
@ -1771,26 +1773,32 @@ export async function validateFormulaAndExtractTreeWithType({
`Field ${name} with ${argPt.dataType} type is found but ${expectedArgType} type is expected` `Field ${name} with ${argPt.dataType} type is found but ${expectedArgType} type is expected`
); );
} else { } else {
let key = '', let key = '';
message = 'Invalid argument type'; const position = i + 1;
let type = '';
if (expectedArgType === FormulaDataTypes.NUMERIC) { if (expectedArgType === FormulaDataTypes.NUMERIC) {
key = 'msg.formula.numericTypeIsExpected'; key = 'msg.formula.typeIsExpected';
message = 'Numeric type is expected'; type = 'numeric';
} else if (expectedArgType === FormulaDataTypes.BOOLEAN) { } else if (expectedArgType === FormulaDataTypes.BOOLEAN) {
key = 'msg.formula.booleanTypeIsExpected'; key = 'msg.formula.typeIsExpected';
message = 'Boolean type is expected'; type = 'boolean';
} else if (expectedArgType === FormulaDataTypes.DATE) { } else if (expectedArgType === FormulaDataTypes.DATE) {
key = 'msg.formula.dateTypeIsExpected'; key = 'msg.formula.typeIsExpected';
message = 'Date type is expected'; type = 'date';
} }
throw new FormulaError( throw new FormulaError(
FormulaErrorType.INVALID_ARG, FormulaErrorType.INVALID_ARG,
{ {
type,
key, key,
position,
calleeName, calleeName,
}, },
message `${calleeName?.toUpperCase()} requires a ${
type || expectedArgType
} at position ${position}`
); );
} }
} }

Loading…
Cancel
Save