Skip to content

Commit

Permalink
add some runtime type-checking in Image.env
Browse files Browse the repository at this point in the history
  • Loading branch information
thundergolfer committed Feb 19, 2025
1 parent 93d7ead commit 2b237e3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2013,8 +2013,12 @@ def env(self, vars: dict[str, str]) -> "_Image":
"""

def build_dockerfile(version: ImageBuilderVersion) -> DockerfileSpec:
commands = ["FROM base"] + [f"ENV {key}={shlex.quote(val)}" for (key, val) in vars.items()]
return DockerfileSpec(commands=commands, context_files={})
try:
env_commands = [f"ENV {key}={shlex.quote(val)}" for (key, val) in vars.items()]
except TypeError:
non_str_keys = [key for key, val in vars.items() if not isinstance(val, str)]
raise InvalidError(f"Environment variables must be strings. Invalid keys: {non_str_keys}")
return DockerfileSpec(commands=["FROM base"] + env_commands, context_files={})

return _Image._from_args(
base_images={"base": self},
Expand Down

0 comments on commit 2b237e3

Please sign in to comment.