error_boundary module

class error_boundary.DjangoSettingErrorBoundary(setting_name='not DEBUG', **kwds)

Bases: error_boundary.ErrorBoundary

Error boundary for Django. Propagate exceptions if DEBUG is true, otherwise suppress.

Parameters:setting_name (str, optional) – The Django setting to determine if we’re in production or not. May optionally have a ‘not ‘ prefix, in which case the setting’s inverted boolean value is used for the decision. Defaults to ‘not DEBUG’, i.e. we’re in production if the DEBUG setting is false.
in_production()
should_propagate_exception(exc_info)
class error_boundary.ErrorBoundary(loggers=None, dont_catch=())

Bases: contextlib.ContextDecorator

Error boundary context manager and decorator.

Parameters:
  • loggers (list, optional) – List of error boundary loggers that exceptions are reported to. Defaults to only the default_logging_logger.
  • dont_catch (list(Exception), optional) – List of exception types that should not be suppressed. Defaults to none (suppress all exceptions).
loggers

See loggers argument.

dont_catch

See dont_catch argument.

get_loggers_for_exception(exc_info)

Get a list of loggers that the exception given by exc_info should be logged to.

You can overwrite this method to fit your needs. The default behaviour is to use all available loggers (see loggers).

Parameters:exc_info (tuple, see sys.exc_info()) –
Returns:List or other iterable of error boundary loggers.
Return type:iterable
log_exception(exc_info)

Log the exception given by exc_info to its loggers.

Note that if one of the loggers raises an exception while trying to log the original exception given by exc_info, this logger exception is printed to stderr and ignored.

Parameters:exc_info (tuple, see sys.exc_info()) –
loggers = (<function get_logging_logger.<locals>.exc_logger>,)
on_no_exception()

Hook that is called if the wrapped user code has not raised any exception.

You can overwrite this method to fit your needs. The default behaviour is to simply do nothing.

on_propagate_exception(propagate_reason, exc_info)

Hook that is called if the wrapped user code has raised an exception that should be propagated (see should_propagate_exception()).

You can overwrite this method to fit your needs. The default behaviour is to simply do nothing.

Parameters:
on_suppress_exception(exc_info)

Hook that is called if the wrapped user code has raised an exception that should be suppressed (see should_propagate_exception()).

You can overwrite this method to fit your needs. The default behaviour is to log the exception if it should be logged (see should_log_exception() and log_exception()).

Parameters:exc_info (tuple, see sys.exc_info()) –
should_log_exception(exc_info)

Decide if the exception given by exc_info should be logged.

You can overwrite this method to fit your needs. The default behaviour is to return True, i.e. log all exceptions.

Parameters:exc_info (tuple, see sys.exc_info()) –
Returns:
Return type:bool
should_propagate_exception(exc_info)

Decide if the exception given by exc_info should be suppressed or propagated.

If it should be suppressed, return a value that evaluates to false.

If it should be propagated, return a value that evaluates to true. The reason is passed as first argument to on_propagate_exception().

You can overwrite this method to fit your needs. The default behaviour is to suppress exceptions whose type is in dont_catch.

Parameters:exc_info (tuple, see sys.exc_info()) –
Returns:A value that evaluates to false if the exception should be suppressed, otherwise a value that evaluates to true.
class error_boundary.ProductionErrorBoundary(is_production, **kwds)

Bases: error_boundary.ErrorBoundary

Error boundary that suppresses exceptions in production, but propagates them during development.

This is the recommended error boundary mode.

Parameters:
should_propagate_exception(exc_info)
error_boundary.django_raven_logger(exc_info)

Error boundary logger that sends errors to Sentry using Raven.

error_boundary.get_logging_logger(logger=None)

Get a Python logging based error boundary logger.

This is the default error boundary logger.

Parameters:logger (logging.Logger, optional) – The logger to use. Defaults to default_logging_logger.
Returns:An error boundary logger.
class error_boundary.unknown_reason

Bases: object

Dummy propagate_reason value used if should_propagate_exception() raises an exception.