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
27
28
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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
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
15
16
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
116
117
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
128
129
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
71
72
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
31
32
33
34
35
36
37
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
49
50
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
40
41
42
43
44
45
46
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
124
125
class OldTemplateWarning(UserWarning, CopierWarning):
    """Template was designed for an older Copier version."""

PathError

Bases: CopierError, ValueError

The path is invalid in the given context.

Source code in copier/errors.py
53
54
class PathError(CopierError, ValueError):
    """The path is invalid in the given context."""

PathNotAbsoluteError

Bases: PathError

The path is not absolute, but it should be.

Source code in copier/errors.py
57
58
59
60
61
class PathNotAbsoluteError(PathError):
    """The path is not absolute, but it should be."""

    def __init__(self, *, path: Path) -> None:
        super().__init__(f'"{path}" is not an absolute path')

PathNotRelativeError

Bases: PathError

The path is not relative, but it should be.

Source code in copier/errors.py
64
65
66
67
68
class PathNotRelativeError(PathError):
    """The path is not relative, but it should be."""

    def __init__(self, *, path: Path) -> None:
        super().__init__(f'"{path}" is not a relative path')

ShallowCloneWarning

Bases: UserWarning, CopierWarning

The template repository is a shallow clone.

Source code in copier/errors.py
132
133
class ShallowCloneWarning(UserWarning, CopierWarning):
    """The template repository is a shallow clone."""

UnknownCopierVersionWarning

Bases: UserWarning, CopierWarning

Cannot determine installed Copier version.

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

UnsafeTemplateError

Bases: CopierError

Unsafe Copier template features are used without explicit consent.

Source code in copier/errors.py
103
104
105
106
107
108
109
110
111
112
class UnsafeTemplateError(CopierError):
    """Unsafe Copier template features are used without explicit consent."""

    def __init__(self, features: Sequence[str]):
        assert features
        s = "s" if len(features) > 1 else ""
        super().__init__(
            f"Template uses potentially unsafe feature{s}: {', '.join(features)}.\n"
            "If you trust this template, consider adding the `--trust` option when running `copier copy/update`."
        )

UnsupportedVersionError

Bases: UserMessageError

Copier version does not support template version.

Source code in copier/errors.py
23
24
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
19
20
class UserMessageError(CopierError):
    """Exit the program giving a message to the user."""