https://pantsbuild.org/ logo
#general
Title
# general
c

cold-vr-15232

03/02/2023, 8:18 AM
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

curved-television-6568

03/02/2023, 2:56 PM
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

refined-addition-53644

03/02/2023, 3:00 PM
I think we should err while having option to set default value? So if it’s
None
then we should err
👍 1
c

curved-television-6568

03/02/2023, 3:00 PM
(I may be in favour of the former, to fail early by default)
yea
r

refined-addition-53644

03/02/2023, 3:00 PM
Even now I do this in python.
I suppose you use
os.getenv
. We should also err if it’s an empty string.
c

cold-vr-15232

03/02/2023, 3:28 PM
Indeed, the default value solved the issue. I probably always had run with the variable set. Thanks!
✔️ 1
p

proud-dentist-22844

03/02/2023, 8:49 PM
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

curved-television-6568

03/02/2023, 10:03 PM
I recall there’s been a PR fixing support for raising/catching exceptions but don’t find it right now.
5 Views