diff --git a/client/web/divkit/src/expressions/eval.ts b/client/web/divkit/src/expressions/eval.ts index ac1e46efd..45839e360 100644 --- a/client/web/divkit/src/expressions/eval.ts +++ b/client/web/divkit/src/expressions/eval.ts @@ -351,9 +351,6 @@ function argsToStr(args: EvalValue[]): string { function evalCallExpression(vars: VariablesMap, expr: CallExpression): EvalValue { const funcName = expr.callee.name; - if (!funcs.has(funcName)) { - throw new Error(`Unknown function name: ${funcName}.`); - } let func: Func | undefined; @@ -362,7 +359,7 @@ function evalCallExpression(vars: VariablesMap, expr: CallExpression): EvalValue if (!funcByArgs.has(funcKey)) { const findRes = findBestMatchedFunc(funcName, args); - if ('expected' in findRes) { + if ('expected' in findRes || 'type' in findRes && findRes.type === 'missing') { const argsType = args.map(arg => typeToString(arg.type)).join(', '); const prefix = `${funcName}(${argsToStr(args)})`; @@ -370,8 +367,10 @@ function evalCallExpression(vars: VariablesMap, expr: CallExpression): EvalValue evalError(prefix, `Non empty argument list is required for function '${funcName}'.`); } else if (findRes.type === 'many') { evalError(prefix, `Function '${funcName}' has no matching override for given argument types: ${argsType}.`); - } else { + } else if (findRes.type === 'few' || findRes.type === 'mismatch') { evalError(prefix, `Function '${funcName}' has no matching override for given argument types: ${argsType}.`); + } else { + evalError(prefix, `Unknown function name: ${funcName}.`); } } func = findRes; diff --git a/client/web/divkit/src/expressions/funcs/funcs.ts b/client/web/divkit/src/expressions/funcs/funcs.ts index a91362ddd..c9e2176e5 100644 --- a/client/web/divkit/src/expressions/funcs/funcs.ts +++ b/client/web/divkit/src/expressions/funcs/funcs.ts @@ -25,6 +25,8 @@ type FuncMatchError = { type: 'many'; expected: number; found: number; +} | { + type: 'missing'; }; // no args @@ -142,7 +144,9 @@ function matchFuncArgs(func: Func, args: EvalValue[]): { export function findBestMatchedFunc(funcName: string, args: EvalValue[]): Func | FuncMatchError { const list = funcs.get(funcName); if (!list) { - throw new Error('Missing function'); + return { + type: 'missing' + }; } let firstError: FuncMatchError | null = null; diff --git a/test_data/expression_test_data/functions_unsupported.json b/test_data/expression_test_data/functions_unsupported.json index f3837d2b8..0087aaef1 100644 --- a/test_data/expression_test_data/functions_unsupported.json +++ b/test_data/expression_test_data/functions_unsupported.json @@ -1,19 +1,5 @@ { "cases": [ - { - "name": "undefinedFunc() => error", - "expression": "@{undefinedFunc()}", - "expected": { - "type": "error", - "value": "Unknown function name: undefinedFunc." - }, - "variables": [], - "platforms": [ - "web" - ], - "description": "Deprecated, make error message more informative", - "deprecated": true - }, { "name": "undefinedFunc() => error", "expression": "@{undefinedFunc()}", @@ -23,7 +9,8 @@ }, "variables": [], "platforms": [ - "android" + "android", + "web" ] } ]