errors.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from __future__ import absolute_import
  2. from __future__ import unicode_literals
  3. VERSION_EXPLANATION = (
  4. 'You might be seeing this error because you\'re using the wrong Compose file version. '
  5. 'Either specify a supported version (e.g "2.2" or "3.3") and place '
  6. 'your service definitions under the `services` key, or omit the `version` key '
  7. 'and place your service definitions at the root of the file to use '
  8. 'version 1.\nFor more on the Compose file format versions, see '
  9. 'https://docs.docker.com/compose/compose-file/')
  10. class ConfigurationError(Exception):
  11. def __init__(self, msg):
  12. self.msg = msg
  13. def __str__(self):
  14. return self.msg
  15. class EnvFileNotFound(ConfigurationError):
  16. pass
  17. class DependencyError(ConfigurationError):
  18. pass
  19. class CircularReference(ConfigurationError):
  20. def __init__(self, trail):
  21. self.trail = trail
  22. @property
  23. def msg(self):
  24. lines = [
  25. "{} in {}".format(service_name, filename)
  26. for (filename, service_name) in self.trail
  27. ]
  28. return "Circular reference:\n {}".format("\n extends ".join(lines))
  29. class ComposeFileNotFound(ConfigurationError):
  30. def __init__(self, supported_filenames):
  31. super(ComposeFileNotFound, self).__init__("""
  32. Can't find a suitable configuration file in this directory or any
  33. parent. Are you in the right directory?
  34. Supported filenames: %s
  35. """ % ", ".join(supported_filenames))
  36. class DuplicateOverrideFileFound(ConfigurationError):
  37. def __init__(self, override_filenames):
  38. self.override_filenames = override_filenames
  39. super(DuplicateOverrideFileFound, self).__init__(
  40. "Multiple override files found: {}. You may only use a single "
  41. "override file.".format(", ".join(override_filenames))
  42. )