Skip to content
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

✨ Better error message when using command as a string #420

Merged
merged 4 commits into from
Feb 21, 2023

Conversation

gabrieldemarmiesse
Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse commented Feb 21, 2023

In [1]: from python_on_whales import docker

In [2]: docker.run("ubuntu", "ls")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 docker.run("ubuntu", "ls")

File /projects/open_source/python-on-whales/python_on_whales/components/container/cli_wrapper.py:1444, in ContainerCLI.run(self, image, command, add_hosts, blkio_weight, blkio_weight_device, cap_add, cap_drop, cgroup_parent, cgroupns, cidfile, cpu_period, cpu_quota, cpu_rt_period, cpu_rt_runtime, cpu_shares, cpus, cpuset_cpus, cpuset_mems, detach, devices, device_cgroup_rules, device_read_bps, device_read_iops, device_write_bps, device_write_iops, content_trust, dns, dns_options, dns_search, domainname, entrypoint, envs, env_files, expose, gpus, groups_add, healthcheck, health_cmd, health_interval, health_retries, health_start_period, health_timeout, hostname, init, interactive, ip, ip6, ipc, isolation, kernel_memory, labels, label_files, link, link_local_ip, log_driver, log_options, mac_address, memory, memory_reservation, memory_swap, memory_swappiness, mounts, name, networks, network_aliases, oom_kill, oom_score_adj, pid, pids_limit, platform, privileged, publish, publish_all, pull, read_only, restart, remove, runtime, security_options, shm_size, sig_proxy, stop_signal, stop_timeout, storage_options, stream, sysctl, tmpfs, tty, ulimit, user, userns, uts, volumes, volume_driver, volumes_from, workdir)
   1441     if isinstance(command, str):
   1442         # boy this is the most common error in the world
   1443         error_message += f" In your case, you can try docker.run('{image}', {command.split()}, ...)."
-> 1444     raise TypeError(error_message)
   1446 image_cli = python_on_whales.components.image.cli_wrapper.ImageCLI(
   1447     self.client_config
   1448 )
   1449 if pull == "missing":

TypeError: When calling docker.run(), the second argument ('command') should be a list, not a string.Here are some examples:docker.run('ubuntu', ['ls']), docker.run('ubuntu', ['cat', '/some/file.txt']) In your case, you can try docker.run('ubuntu', ['ls'], ...).

In [3]: docker.run("ubuntu", ["ls"])
Out[3]: 'bin\nboot\ndev\netc\nhome\nlib\nlib32\nlib64\nlibx32\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar'

@gabrieldemarmiesse gabrieldemarmiesse marked this pull request as ready for review February 21, 2023 21:05
@gabrieldemarmiesse gabrieldemarmiesse enabled auto-merge (squash) February 21, 2023 21:05
@gabrieldemarmiesse gabrieldemarmiesse merged commit f9ff15d into master Feb 21, 2023
@gabrieldemarmiesse gabrieldemarmiesse deleted the 944d39f2-7557-4c3e-9414-66ec4e85e798 branch February 21, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant