errors.py 1.7 KB

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