Skip to content

Commit

Permalink
Merge pull request #4632 from node-red/4625-sf-env-err-handling
Browse files Browse the repository at this point in the history
Add validation and error handling on subflow instance properties
  • Loading branch information
knolleary committed Mar 28, 2024
2 parents 20d067c + 1921343 commit 19dcc3a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 16 additions & 1 deletion packages/node_modules/@node-red/editor-client/src/js/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,22 @@ RED.nodes = (function() {
RED.nodes.registerType("subflow:"+sf.id, {
defaults:{
name:{value:""},
env:{value:[]}
env:{value:[], validate: function(value) {
const errors = []
if (value) {
value.forEach(env => {
const r = RED.utils.validateTypedProperty(env.value, env.type)
if (r !== true) {
errors.push(env.name+': '+r)
}
})
}
if (errors.length === 0) {
return true
} else {
return errors
}
}}
},
icon: function() { return sf.icon||"subflow.svg" },
category: sf.category || "subflows",
Expand Down
14 changes: 11 additions & 3 deletions packages/node_modules/@node-red/runtime/lib/flows/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,22 @@ async function evaluateEnvProperties(flow, env, credentials) {
result = { value: result, __clone__: true}
}
evaluatedEnv[name] = result
} else {
evaluatedEnv[name] = undefined
flow.error(`Error evaluating env property '${name}': ${err.toString()}`)
}
resolve()
});
}))
} else {
value = redUtil.evaluateNodeProperty(value, type, {_flow: flow}, null, null);
if (typeof value === 'object') {
value = { value: value, __clone__: true}
try {
value = redUtil.evaluateNodeProperty(value, type, {_flow: flow}, null, null);
if (typeof value === 'object') {
value = { value: value, __clone__: true}
}
} catch (err) {
value = undefined
flow.error(`Error evaluating env property '${name}': ${err.toString()}`)
}
}
evaluatedEnv[name] = value
Expand Down

0 comments on commit 19dcc3a

Please sign in to comment.