Skip to content

gufo.err.failfast.typematch

TypeMatchFailFast.

TypeMatchFailFast

Bases: BaseFailFast

Fail-fast on the given exception types and optional substrings.

Parameters:

Name Type Description Default
exc Optional[Union[str, Type[BaseException]]]
  • Exception type.
  • string in form "module.name".
  • None to add matchers later.
None
match Optional[str]

Optional substring matcher. Match all when set to None.

None
msg Optional[str]

Optional message to show to log before failfast. %s will be expanded to the exception value.

None

Examples:

Single type:

err.setup(fail_fast=[TypeMatchFailFast(RuntimeError)])

Single type with match:

err.setup(fail_fast=[TypeMatchFailFast(RuntimeError, match="stopped")])

Single type with message:

err.setup(fail_fast=[
    TypeMatchFailFast(RuntimeError, msg="Runtime Error: %s")
])

Chaining:

err.setup(
    fail_fast=[
        TypeMatchFailFast()
        .add_match(DivisionByZero)
        .add_match(ValueError, match="null value")
        .add_match(RuntimeError, msg="Runtime failure: %s")
    ]
)

__exc_to_str(t) staticmethod

Convert exception instance to string class name.

Parameters:

Name Type Description Default
t Type[BaseException]

Exception type

required

Returns:

Type Description
str

Class name in form module.name

add_match(exc, *, match=None, msg=None)

Add new exception type for the fail-fast.

Parameters:

Name Type Description Default
exc Union[str, Type[BaseException]]

Exception type or string in form "module.name".

required
match Optional[str]

Optional substring matcher. Match all when set to None.

None
msg Optional[str]

Optional message to show to log before failfast. %s will be expanded to the exception value.

None

Returns:

Type Description
TypeMatchFailFast

Self reference to allow chaining.

Example
err.setup(
    fail_fast=[
        TypeMatchFailFast()
        .add_match(DivisionByZero)
        .add_match(ValueError, match="null value")
        .add_match(RuntimeError, msg="Runtime failure: %s")
    ]
)

must_die(t, v, tb)

Check if the proceess must die quickly.

Check if exception class matches given substrings.