gitutils.giterror: Errors for gitutils Git repo tools

This module provides a collection of error types relevant to the gitutils package. They are essentially the same as standard error types such as KeyError, TypeError, etc. but with an extra parent of GitutilsError to enable catching all errors specifically raised by this package

exception lfc._vendor.gitutils.giterror.GitutilsAttributeError

Error related to accessing attributes of OptionsDict

Inherits from AttributeError and GitutilsError.

exception lfc._vendor.gitutils.giterror.GitutilsError

Parent error class for gitutils errors

Inherits from Exception

exception lfc._vendor.gitutils.giterror.GitutilsExprError

Exception for invalid @expr

Applies to Gitutils.optitem.getel() or OptionsDict

exception lfc._vendor.gitutils.giterror.GitutilsFileNotFoundError

Exception for missing but required file

Inherits from FileNotFoundError and :class;`GitutilsError`

exception lfc._vendor.gitutils.giterror.GitutilsJSONError

Exception class for errors while parsing JSON files

Inherits from ValueError and GitutilsError

exception lfc._vendor.gitutils.giterror.GitutilsKeyError

Exception for missing key in gitutils

Inherits from KeyError and GitutilsError

exception lfc._vendor.gitutils.giterror.GitutilsNameError

Error for badly named options in OptionsDict

Inherits from NameError and GitutilsError

exception lfc._vendor.gitutils.giterror.GitutilsSystemError

Exception for system errors raised by gitutils

exception lfc._vendor.gitutils.giterror.GitutilsTypeError

Exception for unexpected type of parameter in Gitutils

exception lfc._vendor.gitutils.giterror.GitutilsValueError

Exception for unexpected value of parameter in Gitutils

lfc._vendor.gitutils.giterror.assert_isfile(fname: str)

Ensure that a file exists

Call:
>>> assert_isfile(fname)
Inputs:
fname: str

Name of a file

Raises:

GitutilsFileNotFoundError if fname does not exist

Versions:
  • 2023-10-25 @ddalle: v1.0

lfc._vendor.gitutils.giterror.assert_isinstance(obj, cls_or_tuple, desc=None)

Conveniently check types

Applies isinstance(obj, cls_or_tuple) but also constructs a :class;`TypeError` and appropriate message if test fails

Call:
>>> assert_isinstance(obj, cls, desc=None)
>>> assert_isinstance(obj, cls_tuple, desc=None)
Inputs:
obj: object

Object whose type is checked

cls: type

Single permitted class

cls_tuple: tuple[type]

Tuple of allowed classes

Raises:

GitutilsTypeError

Versions:
  • 2022-09-17 @ddalle: Version 1.0

lfc._vendor.gitutils.giterror.trunc8_fname(fname: str, n: int) str

Truncate string so it fits in current terminal with n to spare

Call:
>>> fshort = trunc8_fname(fname, n)
Inputs:
fname: str

File name or other string to truncate

n: int

Number of chars to reserve for other text

Outputs:
fshort: str

fname or truncated version if fname won’t fit in current terminal width