mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Merge pull request #4632 from node-red/4625-sf-env-err-handling
Add validation and error handling on subflow instance properties
This commit is contained in:
		| @@ -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", | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user