From 9da0c1c8844103a661139f652b6337ff15d3f280 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 3 Apr 2020 19:37:28 +0200 Subject: [PATCH] :zap: Display errors in expressions --- packages/editor-ui/src/components/ExpressionInput.vue | 6 +++--- packages/workflow/src/Workflow.ts | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/editor-ui/src/components/ExpressionInput.vue b/packages/editor-ui/src/components/ExpressionInput.vue index 7ee68be5af..543eb12f22 100644 --- a/packages/editor-ui/src/components/ExpressionInput.vue +++ b/packages/editor-ui/src/components/ExpressionInput.vue @@ -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; diff --git a/packages/workflow/src/Workflow.ts b/packages/workflow/src/Workflow.ts index a63060913c..816c009a1f 100644 --- a/packages/workflow/src/Workflow.ts +++ b/packages/workflow/src/Workflow.ts @@ -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}`); } }