mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 03:46:55 +00:00
Improve error/warning messages w.r.t. YAML quoting (#1205)
* Remove superfluous conversions/assignments. * Improve messages.
This commit is contained in:
@@ -210,13 +210,14 @@ class ExecManager(BaseComposeManager):
|
||||
self.stdin += "\n"
|
||||
|
||||
if self.env is not None:
|
||||
for name, value in list(self.env.items()):
|
||||
for name, value in self.env.items():
|
||||
if not isinstance(value, str):
|
||||
self.fail(
|
||||
"Non-string value found for env option. Ambiguous env options must be "
|
||||
f"wrapped in quotes to avoid them being interpreted. Key: {name}"
|
||||
"wrapped in quotes to avoid them being interpreted when directly specified "
|
||||
"in YAML, or explicitly converted to strings when the option is templated. "
|
||||
f"Key: {name}"
|
||||
)
|
||||
self.env[name] = to_text(value, errors="surrogate_or_strict")
|
||||
|
||||
def get_exec_cmd(self, dry_run: bool) -> list[str]:
|
||||
args = self.get_base_args(plain_progress=True) + ["exec"]
|
||||
|
||||
@@ -296,13 +296,14 @@ class ExecManager(BaseComposeManager):
|
||||
self.stdin += "\n"
|
||||
|
||||
if self.env is not None:
|
||||
for name, value in list(self.env.items()):
|
||||
for name, value in self.env.items():
|
||||
if not isinstance(value, str):
|
||||
self.fail(
|
||||
"Non-string value found for env option. Ambiguous env options must be "
|
||||
f"wrapped in quotes to avoid them being interpreted. Key: {name}"
|
||||
"wrapped in quotes to avoid them being interpreted when directly specified "
|
||||
"in YAML, or explicitly converted to strings when the option is templated. "
|
||||
f"Key: {name}"
|
||||
)
|
||||
self.env[name] = to_text(value, errors="surrogate_or_strict")
|
||||
|
||||
def get_run_cmd(self, dry_run: bool) -> list[str]:
|
||||
args = self.get_base_args(plain_progress=True) + ["run"]
|
||||
|
||||
@@ -221,16 +221,17 @@ def main() -> None:
|
||||
stdin: str | None = client.module.params["stdin"]
|
||||
strip_empty_ends: bool = client.module.params["strip_empty_ends"]
|
||||
tty: bool = client.module.params["tty"]
|
||||
env: dict[str, t.Any] = client.module.params["env"]
|
||||
env: dict[str, t.Any] | None = client.module.params["env"]
|
||||
|
||||
if env is not None:
|
||||
for name, value in list(env.items()):
|
||||
for name, value in env.items():
|
||||
if not isinstance(value, str):
|
||||
client.module.fail_json(
|
||||
msg="Non-string value found for env option. Ambiguous env options must be "
|
||||
f"wrapped in quotes to avoid them being interpreted. Key: {name}"
|
||||
"wrapped in quotes to avoid them being interpreted when directly specified "
|
||||
"in YAML, or explicitly converted to strings when the option is templated. "
|
||||
f"Key: {name}"
|
||||
)
|
||||
env[name] = to_text(value, errors="surrogate_or_strict")
|
||||
|
||||
if command is not None:
|
||||
argv = shlex.split(command)
|
||||
|
||||
@@ -914,8 +914,10 @@ def get_docker_environment(
|
||||
for name, value in env.items():
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(
|
||||
"Non-string value found for env option. "
|
||||
f"Ambiguous env options must be wrapped in quotes to avoid YAML parsing. Key: {name}"
|
||||
"Non-string value found for env option. Ambiguous env options must be "
|
||||
"wrapped in quotes to avoid them being interpreted when directly specified "
|
||||
"in YAML, or explicitly converted to strings when the option is templated. "
|
||||
f"Key: {name}"
|
||||
)
|
||||
env_dict[name] = str(value)
|
||||
elif env is not None and isinstance(env, list):
|
||||
|
||||
Reference in New Issue
Block a user