Tried the new python-dump-source-analysis goal, an...
# general
c
Tried the new python-dump-source-analysis goal, and it doesn't understand use of env(). Bug? `InvalidFieldTypeException: The 'image_tags' field in target apps/_demo_app/docker:demo_app must be an iterable of strings (e.g. a list of strings), but was
['latest', None]
with type
list
.`
😲 1
1
c
what if you give the env a default value?
env("NAME", "default")
seems like the env var was undefined, hence the
None
(guessing, as I don’t see the raw BUILD file contents)
Q: should we err if referencing an undefined env var without a default value provided?
or, as now, let the downstream field types do the type checking…
r
I think we should err while having option to set default value? So if it’s
None
then we should err
👍 1
c
(I may be in favour of the former, to fail early by default)
yea
r
Even now I do this in python.
I suppose you use
os.getenv
. We should also err if it’s an empty string.
c
Indeed, the default value solved the issue. I probably always had run with the variable set. Thanks!
✔️ 1
p
I have occasionally set an env var to an empty string on purpose. The only reason I think it should error is if the env var is not set at all. The semantics of
""
depend on the env var. So, if you didn’t want
""
you could do something like
(env("SOMETHING", "foo") or "foo")
I wonder if you could raise an error in a BUILD file… like
(env("SOMETHING", "default") or raise Exception("SOMETHING is an empty string!"))
Has anyone tried raising exceptions in BUILD files?
c
I recall there’s been a PR fixing support for raising/catching exceptions but don’t find it right now.