Module cruft.exceptions
Contains all custom exceptions raised by cruft.
View Source
"""Contains all custom exceptions raised by cruft."""
from pathlib import Path
from typing import Union
from click import ClickException
class CruftError(ClickException):
"""The base exception for any error originating from the cruft project."""
class UnableToFindCookiecutterTemplate(CruftError):
"""Raised when Cruft is unable to find a cookiecutter template."""
def __init__(self, directory: Union[str, Path]):
if not isinstance(directory, str):
directory = str(directory)
super().__init__(f"Was unable to locate a Cookiecutter template in `{directory}` !")
self.directory = directory
class NoCruftFound(CruftError):
"""Raised when no .cruft.json state is found in the current directory."""
def __init__(self, directory: Union[str, Path]):
if not isinstance(directory, str):
directory = str(directory)
super().__init__(f"Was unable to locate a `.cruft.json` state file in `{directory}` !")
self.directory = directory
class CruftAlreadyPresent(CruftError):
"""Raised when there is an attempt to create a new .cruft.json file but one already exists."""
def __init__(self, file_location: Union[str, Path]):
if not isinstance(file_location, str):
file_location = str(file_location)
super().__init__(f"`.cruft.json` is already defined at `{file_location}` !")
self.file_location = file_location
class InvalidCookiecutterRepository(CruftError):
"""Raised when an invalid cookiecutter repository is provided."""
def __init__(self, cookiecutter_repo: str, details: str = ""):
self.cookiecutter_repo = cookiecutter_repo
super().__init__(
f"Unable to initialize the cookiecutter using {cookiecutter_repo}! {details.strip()}"
)
class ChangesetUnicodeError(CruftError):
"""Raised when `cruft update` is unable to generate the change"""
def __init__(self):
super().__init__(
(
"Unable to interpret changes between current project and cookiecutter template as "
"unicode. Typically a result of hidden binary files in project folder."
)
)
Classes
ChangesetUnicodeError
class ChangesetUnicodeError(
)
Raised when cruft update
is unable to generate the change
View Source
class ChangesetUnicodeError(CruftError):
"""Raised when `cruft update` is unable to generate the change"""
def __init__(self):
super().__init__(
(
"Unable to interpret changes between current project and cookiecutter template as "
"unicode. Typically a result of hidden binary files in project folder."
)
)
Ancestors (in MRO)
- cruft.exceptions.CruftError
- click.exceptions.ClickException
- builtins.Exception
- builtins.BaseException
Class variables
args
exit_code
Methods
format_message
def format_message(
self
) -> str
View Source
def format_message(self) -> str:
return self.message
show
def show(
self,
file: Union[IO[Any], NoneType] = None
) -> None
View Source
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)
with_traceback
def with_traceback(
...
)
Exception.with_traceback(tb) --
set self.traceback to tb and return self.
CruftAlreadyPresent
class CruftAlreadyPresent(
file_location: Union[str, pathlib.Path]
)
Raised when there is an attempt to create a new .cruft.json file but one already exists.
View Source
class CruftAlreadyPresent(CruftError):
"""Raised when there is an attempt to create a new .cruft.json file but one already exists."""
def __init__(self, file_location: Union[str, Path]):
if not isinstance(file_location, str):
file_location = str(file_location)
super().__init__(f"`.cruft.json` is already defined at `{file_location}` !")
self.file_location = file_location
Ancestors (in MRO)
- cruft.exceptions.CruftError
- click.exceptions.ClickException
- builtins.Exception
- builtins.BaseException
Class variables
args
exit_code
Methods
format_message
def format_message(
self
) -> str
View Source
def format_message(self) -> str:
return self.message
show
def show(
self,
file: Union[IO[Any], NoneType] = None
) -> None
View Source
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)
with_traceback
def with_traceback(
...
)
Exception.with_traceback(tb) --
set self.traceback to tb and return self.
CruftError
class CruftError(
message: str
)
The base exception for any error originating from the cruft project.
View Source
class CruftError(ClickException):
"""The base exception for any error originating from the cruft project."""
Ancestors (in MRO)
- click.exceptions.ClickException
- builtins.Exception
- builtins.BaseException
Descendants
- cruft.exceptions.UnableToFindCookiecutterTemplate
- cruft.exceptions.NoCruftFound
- cruft.exceptions.CruftAlreadyPresent
- cruft.exceptions.InvalidCookiecutterRepository
- cruft.exceptions.ChangesetUnicodeError
Class variables
args
exit_code
Methods
format_message
def format_message(
self
) -> str
View Source
def format_message(self) -> str:
return self.message
show
def show(
self,
file: Union[IO[Any], NoneType] = None
) -> None
View Source
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)
with_traceback
def with_traceback(
...
)
Exception.with_traceback(tb) --
set self.traceback to tb and return self.
InvalidCookiecutterRepository
class InvalidCookiecutterRepository(
cookiecutter_repo: str,
details: str = ''
)
Raised when an invalid cookiecutter repository is provided.
View Source
class InvalidCookiecutterRepository(CruftError):
"""Raised when an invalid cookiecutter repository is provided."""
def __init__(self, cookiecutter_repo: str, details: str = ""):
self.cookiecutter_repo = cookiecutter_repo
super().__init__(
f"Unable to initialize the cookiecutter using {cookiecutter_repo}! {details.strip()}"
)
Ancestors (in MRO)
- cruft.exceptions.CruftError
- click.exceptions.ClickException
- builtins.Exception
- builtins.BaseException
Class variables
args
exit_code
Methods
format_message
def format_message(
self
) -> str
View Source
def format_message(self) -> str:
return self.message
show
def show(
self,
file: Union[IO[Any], NoneType] = None
) -> None
View Source
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)
with_traceback
def with_traceback(
...
)
Exception.with_traceback(tb) --
set self.traceback to tb and return self.
NoCruftFound
class NoCruftFound(
directory: Union[str, pathlib.Path]
)
Raised when no .cruft.json state is found in the current directory.
View Source
class NoCruftFound(CruftError):
"""Raised when no .cruft.json state is found in the current directory."""
def __init__(self, directory: Union[str, Path]):
if not isinstance(directory, str):
directory = str(directory)
super().__init__(f"Was unable to locate a `.cruft.json` state file in `{directory}` !")
self.directory = directory
Ancestors (in MRO)
- cruft.exceptions.CruftError
- click.exceptions.ClickException
- builtins.Exception
- builtins.BaseException
Class variables
args
exit_code
Methods
format_message
def format_message(
self
) -> str
View Source
def format_message(self) -> str:
return self.message
show
def show(
self,
file: Union[IO[Any], NoneType] = None
) -> None
View Source
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)
with_traceback
def with_traceback(
...
)
Exception.with_traceback(tb) --
set self.traceback to tb and return self.
UnableToFindCookiecutterTemplate
class UnableToFindCookiecutterTemplate(
directory: Union[str, pathlib.Path]
)
Raised when Cruft is unable to find a cookiecutter template.
View Source
class UnableToFindCookiecutterTemplate(CruftError):
"""Raised when Cruft is unable to find a cookiecutter template."""
def __init__(self, directory: Union[str, Path]):
if not isinstance(directory, str):
directory = str(directory)
super().__init__(f"Was unable to locate a Cookiecutter template in `{directory}` !")
self.directory = directory
Ancestors (in MRO)
- cruft.exceptions.CruftError
- click.exceptions.ClickException
- builtins.Exception
- builtins.BaseException
Class variables
args
exit_code
Methods
format_message
def format_message(
self
) -> str
View Source
def format_message(self) -> str:
return self.message
show
def show(
self,
file: Union[IO[Any], NoneType] = None
) -> None
View Source
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None:
if file is None:
file = get_text_stderr()
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=self.show_color,
)
with_traceback
def with_traceback(
...
)
Exception.with_traceback(tb) --
set self.traceback to tb and return self.