Skip to content

Do not warn about missing values if a fallback is provided #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qc00 opened this issue Mar 31, 2023 · 2 comments
Open

Do not warn about missing values if a fallback is provided #76

qc00 opened this issue Mar 31, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@qc00
Copy link

qc00 commented Mar 31, 2023

Is your feature request related to a problem? Please describe.
I want to allow many values to be overridden using vars but still provide defaults/fallback values when the var is not set. This is possible with the "or" operator:

${{vars.optional_config || 'default value'}}

However, this currently generates a warning "Context access might be invalid: optional_config"

Describe the solution you'd like
The static analyser should detect that the || operator provides a default and not generate a warning.

Alternatively, provide a function (e.g. val_or_default(vars.optional_config, 'default value')) to make the user's intention explicit to the linter.

@qc00 qc00 added the enhancement New feature or request label Mar 31, 2023
@christopher-caldwell
Copy link

Possibly related, what are you supposed to do if you don't have a fallback? If a value is required, to the point where the action should error if not present, is there a way to achieve this?

@qc00
Copy link
Author

qc00 commented Mar 31, 2023

@christopher-caldwell Good point! Instead of val_or_default, the function can have the signature required_value(expr, [default]). Then if the variable is not set and the default argument is not supplied, the workflow fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Triaged 📝
Development

No branches or pull requests

2 participants