mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
Merge pull request #114 from orchardup/refactor-errors
Extract error text into errors.py
This commit is contained in:
commit
3ed9e16558
@ -15,7 +15,7 @@ from ..service import ConfigError
|
|||||||
from .docopt_command import DocoptCommand
|
from .docopt_command import DocoptCommand
|
||||||
from .formatter import Formatter
|
from .formatter import Formatter
|
||||||
from .utils import cached_property, docker_url, call_silently, is_mac, is_ubuntu
|
from .utils import cached_property, docker_url, call_silently, is_mac, is_ubuntu
|
||||||
from .errors import UserError
|
from . import errors
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -28,31 +28,15 @@ class Command(DocoptCommand):
|
|||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
if call_silently(['which', 'docker']) != 0:
|
if call_silently(['which', 'docker']) != 0:
|
||||||
if is_mac():
|
if is_mac():
|
||||||
raise UserError("""
|
raise errors.DockerNotFoundMac()
|
||||||
Couldn't connect to Docker daemon. You might need to install docker-osx:
|
|
||||||
|
|
||||||
https://github.com/noplay/docker-osx
|
|
||||||
""")
|
|
||||||
elif is_ubuntu():
|
elif is_ubuntu():
|
||||||
raise UserError("""
|
raise errors.DockerNotFoundUbuntu()
|
||||||
Couldn't connect to Docker daemon. You might need to install Docker:
|
|
||||||
|
|
||||||
http://docs.docker.io/en/latest/installation/ubuntulinux/
|
|
||||||
""")
|
|
||||||
else:
|
else:
|
||||||
raise UserError("""
|
raise errors.DockerNotFoundGeneric()
|
||||||
Couldn't connect to Docker daemon. You might need to install Docker:
|
|
||||||
|
|
||||||
http://docs.docker.io/en/latest/installation/
|
|
||||||
""")
|
|
||||||
elif call_silently(['which', 'docker-osx']) == 0:
|
elif call_silently(['which', 'docker-osx']) == 0:
|
||||||
raise UserError("Couldn't connect to Docker daemon - you might need to run `docker-osx shell`.")
|
raise errors.ConnectionErrorDockerOSX()
|
||||||
else:
|
else:
|
||||||
raise UserError("""
|
raise errors.ConnectionErrorGeneric(self.client.base_url)
|
||||||
Couldn't connect to Docker daemon at %s - is it running?
|
|
||||||
|
|
||||||
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
|
|
||||||
""" % self.client.base_url)
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def client(self):
|
def client(self):
|
||||||
@ -66,16 +50,13 @@ If it's at a non-standard location, specify the URL with the DOCKER_HOST environ
|
|||||||
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
log.error("Can't find %s. Are you in the right directory?", os.path.basename(e.filename))
|
raise errors.FigFileNotFound(os.path.basename(e.filename))
|
||||||
else:
|
raise errors.UserError(six.text_type(e))
|
||||||
log.error(e)
|
|
||||||
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return Project.from_config(self.project_name, config, self.client)
|
return Project.from_config(self.project_name, config, self.client)
|
||||||
except ConfigError as e:
|
except ConfigError as e:
|
||||||
raise UserError(six.text_type(e))
|
raise errors.UserError(six.text_type(e))
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def project_name(self):
|
def project_name(self):
|
||||||
|
@ -8,3 +8,53 @@ class UserError(Exception):
|
|||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
|
|
||||||
|
class DockerNotFoundMac(UserError):
|
||||||
|
def __init__(self):
|
||||||
|
super(DockerNotFoundMac, self).__init__("""
|
||||||
|
Couldn't connect to Docker daemon. You might need to install docker-osx:
|
||||||
|
|
||||||
|
https://github.com/noplay/docker-osx
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
class DockerNotFoundUbuntu(UserError):
|
||||||
|
def __init__(self):
|
||||||
|
super(DockerNotFoundUbuntu, self).__init__("""
|
||||||
|
Couldn't connect to Docker daemon. You might need to install Docker:
|
||||||
|
|
||||||
|
http://docs.docker.io/en/latest/installation/ubuntulinux/
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
class DockerNotFoundGeneric(UserError):
|
||||||
|
def __init__(self):
|
||||||
|
super(DockerNotFoundGeneric, self).__init__("""
|
||||||
|
Couldn't connect to Docker daemon. You might need to install Docker:
|
||||||
|
|
||||||
|
http://docs.docker.io/en/latest/installation/
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionErrorDockerOSX(UserError):
|
||||||
|
def __init__(self):
|
||||||
|
super(ConnectionErrorDockerOSX, self).__init__("""
|
||||||
|
Couldn't connect to Docker daemon - you might need to run `docker-osx shell`.
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionErrorGeneric(UserError):
|
||||||
|
def __init__(self, url):
|
||||||
|
super(ConnectionErrorGeneric, self).__init__("""
|
||||||
|
Couldn't connect to Docker daemon at %s - is it running?
|
||||||
|
|
||||||
|
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
|
||||||
|
""" % url)
|
||||||
|
|
||||||
|
|
||||||
|
class FigFileNotFound(UserError):
|
||||||
|
def __init__(self, filename):
|
||||||
|
super(FigFileNotFound, self).__init__("""
|
||||||
|
Can't find %s. Are you in the right directory?
|
||||||
|
""" % filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user