obs: this feature is not asking to serialize env variable values!
I noticed that every time when I import a flows.json
, in order to avoid late runtime issues, I must search for $env
(jsonata) or env.get
(function node) just to determine which environment variables my flow needs. After that, I also need to check which ones are actually mandatory, since there are situations where a fallback value is used when a particular env variable is not set. To mitigate this issue, developers can write a document describing all env variables their flow needs, however this solution won't solve runtime issues due to missing env variables because people can still forget to set some values. To solve this other issue, developers can add a function node that throws an exception if any of the env variables are missing, however they will only see this error if a message is processed by this node, which may not even happen, or happen too late.
So, since I could not find a solution in the editor that would help me to determine which env variables my flows require, my suggestion is to include this information in the exported flows.json
, in a section where the developer, editor and runtime, can easily determine which environment variables are necessary, similarly as this feature, which includes the dependencies a flow requires. For example, in a exported flow.json
there would exist a new object describing the environment variables
[
{
"id": "5bb3c78cfb5d197f"
"type": "global-config",
"modules": {...},
"environment_variables": [
{
"key" : "MY_ENV",
"value": "fallback value", // THIS IS NOT SERIALIZING THE VALUE. IT IS A FALLBACK ONE WHICH IS ALWAYS OVERWRITTEN BY THE CONFIGURED VALUE
"description": "this environment variable is used to...",
"required": false // the editor and runtime won't require this one to be added before deploying the flow
},
{
"key" : "MY_REQUIRED_ENV",
"description": "this environment variable is used to...",
"required": true // the editor and runtime will require this one to be added before deploying the flow
},
]
}
]
editor error
When importing a flow that requires env variables, the Editor will notify the User about it, and tell him/her which ones must be set in his environment.
This will remove runtime errors due to missing environment variables.
runtime error
A runtime error is also thrown when a flow configured with required env variables can't find values in the environment.
When the runtime finds all environment values in the environment, the flow starts
...
Checking environment variables
Loading nodes
Loading plugins
Flows started
...
When the runtime can't find at least 1 required environment variable value, an exception is raised and the flow won't start. It is similar as when a dependency is missing.
Checking environment variables
Error: the following env variable MY_REQUIRED_ENV_VAR is not set. Please, set it in the environment before running this flow.
When a flow has an environment variable reference that ins't listed in the global config, a different error will be raised
Checking environment variables
Error: a reference to an environment variable called MY_UNCONFIGURABLE_ENV_VAR has been found at {node_id}. Please, configure this env variable in the global config.