1# -*- coding: utf-8 -*-
2
3"""All exceptions used in the Cookiecutter code base are defined here."""
4
5
6class CookiecutterException(Exception):
7    """
8    Base exception class.
9
10    All Cookiecutter-specific exceptions should subclass this class.
11    """
12
13
14class NonTemplatedInputDirException(CookiecutterException):
15    """
16    Exception for when a project's input dir is not templated.
17
18    The name of the input directory should always contain a string that is
19    rendered to something else, so that input_dir != output_dir.
20    """
21
22
23class UnknownTemplateDirException(CookiecutterException):
24    """
25    Exception for ambiguous project template directory.
26
27    Raised when Cookiecutter cannot determine which directory is the project
28    template, e.g. more than one dir appears to be a template dir.
29    """
30
31    # unused locally
32
33
34class MissingProjectDir(CookiecutterException):
35    """
36    Exception for missing generated project directory.
37
38    Raised during cleanup when remove_repo() can't find a generated project
39    directory inside of a repo.
40    """
41
42    # unused locally
43
44
45class ConfigDoesNotExistException(CookiecutterException):
46    """
47    Exception for missing config file.
48
49    Raised when get_config() is passed a path to a config file, but no file
50    is found at that path.
51    """
52
53
54class InvalidConfiguration(CookiecutterException):
55    """
56    Exception for invalid configuration file.
57
58    Raised if the global configuration file is not valid YAML or is
59    badly constructed.
60    """
61
62
63class UnknownRepoType(CookiecutterException):
64    """
65    Exception for unknown repo types.
66
67    Raised if a repo's type cannot be determined.
68    """
69
70
71class VCSNotInstalled(CookiecutterException):
72    """
73    Exception when version control is unavailable.
74
75    Raised if the version control system (git or hg) is not installed.
76    """
77
78
79class ContextDecodingException(CookiecutterException):
80    """
81    Exception for failed JSON decoding.
82
83    Raised when a project's JSON context file can not be decoded.
84    """
85
86
87class OutputDirExistsException(CookiecutterException):
88    """
89    Exception for existing output directory.
90
91    Raised when the output directory of the project exists already.
92    """
93
94
95class InvalidModeException(CookiecutterException):
96    """
97    Exception for incompatible modes.
98
99    Raised when cookiecutter is called with both `no_input==True` and
100    `replay==True` at the same time.
101    """
102
103
104class FailedHookException(CookiecutterException):
105    """
106    Exception for hook failures.
107
108    Raised when a hook script fails.
109    """
110
111
112class UndefinedVariableInTemplate(CookiecutterException):
113    """
114    Exception for out-of-scope variables.
115
116    Raised when a template uses a variable which is not defined in the
117    context.
118    """
119
120    def __init__(self, message, error, context):
121        """Exception for out-of-scope variables."""
122        self.message = message
123        self.error = error
124        self.context = context
125
126    def __str__(self):
127        """Text representation of UndefinedVariableInTemplate."""
128        return (
129            "{self.message}. "
130            "Error message: {self.error.message}. "
131            "Context: {self.context}"
132        ).format(**locals())
133
134
135class UnknownExtension(CookiecutterException):
136    """
137    Exception for un-importable extention.
138
139    Raised when an environment is unable to import a required extension.
140    """
141
142
143class RepositoryNotFound(CookiecutterException):
144    """
145    Exception for missing repo.
146
147    Raised when the specified cookiecutter repository doesn't exist.
148    """
149
150
151class RepositoryCloneFailed(CookiecutterException):
152    """
153    Exception for un-cloneable repo.
154
155    Raised when a cookiecutter template can't be cloned.
156    """
157
158
159class InvalidZipRepository(CookiecutterException):
160    """
161    Exception for bad zip repo.
162
163    Raised when the specified cookiecutter repository isn't a valid
164    Zip archive.
165    """
166