Skip to content

errors.py

Custom exceptions used by Copier.

ConfigFileError

Bases: ValueError, CopierError

Parent class defining problems with the config file.

Source code in copier/errors.py
29
30
class ConfigFileError(ValueError, CopierError):
    """Parent class defining problems with the config file."""

CopierAnswersInterrupt

Bases: CopierError, KeyboardInterrupt

CopierAnswersInterrupt is raised during interactive question prompts.

It typically follows a KeyboardInterrupt (i.e. ctrl-c) and provides an opportunity for the caller to conduct additional cleanup, such as writing the partially completed answers to a file.

Attributes:

Name Type Description
answers

AnswersMap that contains the partially completed answers object.

last_question

Question representing the last_question that was asked at the time the interrupt was raised.

template

Template that was being processed for answers.

Source code in copier/errors.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class CopierAnswersInterrupt(CopierError, KeyboardInterrupt):
    """CopierAnswersInterrupt is raised during interactive question prompts.

    It typically follows a KeyboardInterrupt (i.e. ctrl-c) and provides an
    opportunity for the caller to conduct additional cleanup, such as writing
    the partially completed answers to a file.

    Attributes:
        answers:
            AnswersMap that contains the partially completed answers object.

        last_question:
            Question representing the last_question that was asked at the time
            the interrupt was raised.

        template:
            Template that was being processed for answers.

    """

    def __init__(
        self, answers: "AnswersMap", last_question: "Question", template: "Template"
    ) -> None:
        self.answers = answers
        self.last_question = last_question
        self.template = template

CopierError

Bases: Exception

Base class for all other Copier errors.

Source code in copier/errors.py
17
18
class CopierError(Exception):
    """Base class for all other Copier errors."""

CopierWarning

Bases: Warning

Base class for all other Copier warnings.

Source code in copier/errors.py
102
103
class CopierWarning(Warning):
    """Base class for all other Copier warnings."""

DirtyLocalWarning

Bases: UserWarning, CopierWarning

Changes and untracked files present in template.

Source code in copier/errors.py
114
115
class DirtyLocalWarning(UserWarning, CopierWarning):
    """Changes and untracked files present in template."""

ExtensionNotFoundError

Bases: UserMessageError

Extensions listed in the configuration could not be loaded.

Source code in copier/errors.py
69
70
class ExtensionNotFoundError(UserMessageError):
    """Extensions listed in the configuration could not be loaded."""

InvalidConfigFileError

Bases: ConfigFileError

Indicates that the config file is wrong.

Source code in copier/errors.py
33
34
35
36
37
38
39
class InvalidConfigFileError(ConfigFileError):
    """Indicates that the config file is wrong."""

    def __init__(self, conf_path: Path, quiet: bool):
        msg = str(conf_path)
        printf_exception(self, "INVALID CONFIG FILE", msg=msg, quiet=quiet)
        super().__init__(msg)

InvalidTypeError

Bases: TypeError, CopierError

The question type is not among the supported ones.

Source code in copier/errors.py
51
52
class InvalidTypeError(TypeError, CopierError):
    """The question type is not among the supported ones."""

MultipleConfigFilesError

Bases: ConfigFileError

Both copier.yml and copier.yaml found, and that's an error.

Source code in copier/errors.py
42
43
44
45
46
47
48
class MultipleConfigFilesError(ConfigFileError):
    """Both copier.yml and copier.yaml found, and that's an error."""

    def __init__(self, conf_paths: "PathSeq"):
        msg = str(conf_paths)
        printf_exception(self, "MULTIPLE CONFIG FILES", msg=msg)
        super().__init__(msg)

OldTemplateWarning

Bases: UserWarning, CopierWarning

Template was designed for an older Copier version.

Source code in copier/errors.py
110
111
class OldTemplateWarning(UserWarning, CopierWarning):
    """Template was designed for an older Copier version."""

PathNotAbsoluteError

Bases: _PathValueError, CopierError

The path is not absolute, but it should be.

Source code in copier/errors.py
55
56
57
58
59
class PathNotAbsoluteError(_PathValueError, CopierError):
    """The path is not absolute, but it should be."""

    code = "path.not_absolute"
    msg_template = '"{path}" is not an absolute path'

PathNotRelativeError

Bases: _PathValueError, CopierError

The path is not relative, but it should be.

Source code in copier/errors.py
62
63
64
65
66
class PathNotRelativeError(_PathValueError, CopierError):
    """The path is not relative, but it should be."""

    code = "path.not_relative"
    msg_template = '"{path}" is not a relative path'

UnknownCopierVersionWarning

Bases: UserWarning, CopierWarning

Cannot determine installed Copier version.

Source code in copier/errors.py
106
107
class UnknownCopierVersionWarning(UserWarning, CopierWarning):
    """Cannot determine installed Copier version."""

UnsupportedVersionError

Bases: UserMessageError

Copier version does not support template version.

Source code in copier/errors.py
25
26
class UnsupportedVersionError(UserMessageError):
    """Copier version does not support template version."""

UserMessageError

Bases: CopierError

Exit the program giving a message to the user.

Source code in copier/errors.py
21
22
class UserMessageError(CopierError):
    """Exit the program giving a message to the user."""