Skip to content

Commit

Permalink
(feat) improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed Mar 1, 2021
1 parent 3054814 commit 5ef8529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions dwn/cli/commands/base.py
Expand Up @@ -61,6 +61,11 @@ def run(name, extra_args):
return

console.info(f'found plan for [cyan]{name}[/]')
if (c := len(plan.container.containers())) > 0:
console.error(f'plan [bold]{name}[/] already has [b]{c}[/] containers running')
console.info(f'use [bold]dwn show[/] to see running plans. [bold]dwn stop <plan>[/] to stop')
return

plan.add_commands(extra_args) if extra_args else None

for v, o in plan.volumes.items():
Expand All @@ -82,8 +87,14 @@ def run(name, extra_args):
return

console.info('streaming container logs')
for log in service.attach(stdout=True, stderr=True, stream=True, logs=True):
click.echo(log.rstrip())
try:
for log in service.attach(stdout=True, stderr=True, stream=True, logs=True):
click.echo(log.rstrip())
except docker.errors.NotFound:
console.warn(f'unable to stream logs. service container '
f'[bold]{service.name}[/] may have already stopped')
plan.container.stop()
return

# if log streaming is done, we're assuming the container exited too,
# so cleanup anything else.
Expand Down
2 changes: 2 additions & 0 deletions dwn/plan.py
Expand Up @@ -372,6 +372,8 @@ def run(self) -> models.containers.Container:
opts = self.plan.run_options()
opts['name'] = self.get_container_name()

console.debug(f'using image tag [bold]{self.plan.image_version()}[/] for plan')

container = self.get_client(). \
containers.run(self.plan.image_version(), network=config.net_name(), **opts)

Expand Down

0 comments on commit 5ef8529

Please sign in to comment.