1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-11-10 12:35:46 +03:00

Display errors in expressions

This commit is contained in:
Jan Oberhauser 2020-04-03 19:37:28 +02:00
parent 1e484d5072
commit 9da0c1c884
2 changed files with 6 additions and 10 deletions

View File

@ -166,11 +166,11 @@ export default mixins(
let returnValue;
try {
returnValue = this.resolveExpression(`=${variableName}`);
} catch (e) {
return 'invalid';
} catch (error) {
return `[invalid (${error.message})]`;
}
if (returnValue === undefined) {
return 'not found';
return '[not found]';
}
return returnValue;

View File

@ -156,7 +156,8 @@ export class Workflow {
* @memberof Workflow
*/
convertObjectValueToString(value: object): string {
return `[Object: ${JSON.stringify(value)}]`;
const typeName = Array.isArray(value) ? 'Array' : 'Object';
return `[${typeName}: ${JSON.stringify(value)}]`;
}
@ -906,18 +907,13 @@ export class Workflow {
try {
const returnValue = tmpl.tmpl(parameterValue, data);
if (returnValue !== null && typeof returnValue === 'object') {
if (Object.keys(returnValue).length === 0) {
// When expression is incomplete it returns a Proxy which causes problems.
// Catch it with this code and return a proper error.
throw new Error('Expression is not valid.');
}
if (returnObjectAsString === true) {
return this.convertObjectValueToString(returnValue);
}
}
return returnValue;
} catch (e) {
throw new Error('Expression is not valid.');
throw new Error(`Expression is not valid: ${e.message}`);
}
}