errors.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. VERSION_EXPLANATION = (
  4. 'Either specify a version of "2" (or "2.0") and place your service '
  5. 'definitions under the `services` key, or omit the `version` key and place '
  6. 'your service definitions at the root of the file to use version 1.\n'
  7. 'For more on the Compose file format versions, see '
  8. 'https://docs.docker.com/compose/compose-file/')
  9. class ConfigurationError(Exception):
  10. def __init__(self, msg):
  11. self.msg = msg
  12. def __str__(self):
  13. return self.msg
  14. class DependencyError(ConfigurationError):
  15. pass
  16. class CircularReference(ConfigurationError):
  17. def __init__(self, trail):
  18. self.trail = trail
  19. @property
  20. def msg(self):
  21. lines = [
  22. "{} in {}".format(service_name, filename)
  23. for (filename, service_name) in self.trail
  24. ]
  25. return "Circular reference:\n {}".format("\n extends ".join(lines))
  26. class ComposeFileNotFound(ConfigurationError):
  27. def __init__(self, supported_filenames):
  28. super(ComposeFileNotFound, self).__init__("""
  29. Can't find a suitable configuration file in this directory or any
  30. parent. Are you in the right directory?
  31. Supported filenames: %s
  32. """ % ", ".join(supported_filenames))