{"record":{"id":"551c8ebab84aec62","repo":"n8n-io/n8n","slug":"expected-two-arguments-value-defaultvalue-for-t","errorCode":null,"errorMessage":"expected two arguments (value, defaultValue) for this function","messagePattern":"expected two arguments \\(value, defaultValue\\) for this function","errorType":"exception","errorClass":"ExpressionExtensionError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/extensions/function-extensions.ts","lineNumber":51,"sourceCode":"\t}\n\treturn result;\n};\n\nconst average = (...args: number[]) => {\n\treturn aAverage(args);\n};\n\nconst not = (value: unknown): boolean => {\n\treturn !value;\n};\n\nfunction ifEmpty<T, V>(value: V, defaultValue: T) {\n\tif (arguments.length !== 2) {\n\t\t// DIVERGENCE from packages/workflow/src/extensions/extended-functions.ts:\n\t\t// The original throws ExpressionError (from ExecutionBaseError). The runtime\n\t\t// uses ExpressionExtensionError because the full ExpressionError class is not\n\t\t// available in the extensions layer — only a minimal shim exists in safe-globals.\n\t\tthrow new ExpressionExtensionError(\n\t\t\t'expected two arguments (value, defaultValue) for this function',\n\t\t);\n\t}\n\tif (value === undefined || value === null || value === '') {\n\t\treturn defaultValue;\n\t}\n\tif (typeof value === 'object') {\n\t\tif (Array.isArray(value) && !value.length) {\n\t\t\treturn defaultValue;\n\t\t}\n\t\tif (!Object.keys(value).length) {\n\t\t\treturn defaultValue;\n\t\t}\n\t}\n\treturn value;\n}\n\nifEmpty.doc = {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/extensions/function-extensions.ts#L33-L69","documentation":"`ifEmpty(value, defaultValue)` requires exactly two arguments; the body checks `arguments.length !== 2` and throws if it is not. The runtime shim cannot fall back because the whole point of the function is to supply a default.","triggerScenarios":"Calling `.ifEmpty()` with no default, or with only one argument; using `.ifEmpty` as a bare property reference instead of a call.","commonSituations":"Forgot to provide the fallback value; copied a pattern from a language where the default is optional; field renamed so the argument expression resolved to nothing.","solutions":["Always pass a default value: `.ifEmpty('N/A')`.","Double-check the expression has both operands inside the parentheses.","If emptiness is acceptable, omit `.ifEmpty()` entirely rather than calling it half-formed."],"exampleFix":"// before\n{{ $json.note.ifEmpty() }}\n// after\n{{ $json.note.ifEmpty('N/A') }}","handlingStrategy":"validation","validationCode":"// Ensure both operands are present before constructing the expression:\nif ($json.value === undefined || $json.fallback === undefined) {\n  throw new Error('ifEmpty(): both value and defaultValue are required');\n}\nreturn $json;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a default: `.ifEmpty('N/A')`.","Double-check both operands are inside the parentheses.","If emptiness is acceptable, simply omit the call."],"tags":["expression","arguments","argument-count"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}