Mandatory environment variables / environment variables validation

Hello, in my project manifest I have mandatory environment variables that I don’t want to fallback to default values (since there is no sensible default).

Right now the only way I have to make them mandatory is to fatalError if the variable is missing (or invalid). Which is not very user friendly since it prints the entire stack trace to the console, which is meaningless. We have to scroll up the terminal to find the actual fatal error message.

Would it be possible to add some sort of environment variables validation?

Technically? Probably. But Project manifests are compiled to generate the JSON, so we’d need to parse the compilation error to present it in a nicer way. I’m not sure this is something we want to take on.

You might be better served by running pre-generation checks yourself using a script:

# generate.sh
# check environment variables are present
tuist generate
1 Like

Also, if you are expecting those variables to be present in environments, I’d recommend to use something like Mise to configure them automatically, such that you don’t need logic to fail in case of absence.

Yeah we ended up doing that, a Python script akin to a makefile for the project.

Here, I use environment variables to setup variants of the app at generation time. They are used like this: TUIST_APP_BRAND=xxx TUIST_APP_ENV=yyy tuist generate.

The app cannot be generated without a brand and an “env”, this is why I need generation to fail if the variables are missing or invalid. How would Mise help me? Would it just give a better error message?

And before you ask why I’m doing this, it’s a workaround for a bug in Xcode that appears when there are configurations other than Debug and Release (so I created my own configurations at generation time).