Browse Source

fix: formula - better error message with parameter position

pull/7463/head
Pranav C 9 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",
"hintEnd": "Formulas.",
"noSuggestedFormulaFound": "No suggested formula found",
"typeIsExpected": "{calleeName} requires a {type} at position {position}",
"numericTypeIsExpected": "Numeric type is expected",
"stringTypeIsExpected": "String type is expected",
"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(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.numericTypeIsExpected',
key: 'msg.formula.typeIsExpected',
type: 'Numeric',
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`
);
} else {
let key = '',
message = 'Invalid argument type';
let key = '';
const position = i + 1;
let type = '';
if (expectedArgType === FormulaDataTypes.NUMERIC) {
key = 'msg.formula.numericTypeIsExpected';
message = 'Numeric type is expected';
key = 'msg.formula.typeIsExpected';
type = 'numeric';
} else if (expectedArgType === FormulaDataTypes.BOOLEAN) {
key = 'msg.formula.booleanTypeIsExpected';
message = 'Boolean type is expected';
key = 'msg.formula.typeIsExpected';
type = 'boolean';
} else if (expectedArgType === FormulaDataTypes.DATE) {
key = 'msg.formula.dateTypeIsExpected';
message = 'Date type is expected';
key = 'msg.formula.typeIsExpected';
type = 'date';
}
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
type,
key,
position,
calleeName,
},
message
`${calleeName?.toUpperCase()} requires a ${
type || expectedArgType
} at position ${position}`
);
}
}

Loading…
Cancel
Save