maestral.errorhandling

This module contains methods and decorators to convert OSErrors and Dropbox SDK exceptions to instances of maestral.exceptions.MaestralApiError.

Module Contents

maestral.errorhandling.CONNECTION_ERRORS[source]
maestral.errorhandling.convert_api_errors(dbx_path=None, local_path=None)[source]

A context manager that catches and re-raises instances of OSError and dropbox.exceptions.DropboxException as maestral.exceptions.MaestralApiError or ConnectionError.

Parameters
  • dbx_path (str | None) – Dropbox path associated with the error.

  • local_path (str | None) – Local path associated with the error.

Return type

Iterator[None]

maestral.errorhandling.os_to_maestral_error(exc, dbx_path=None, local_path=None)[source]

Converts a OSError to a maestral.exceptions.MaestralApiError and tries to add a reasonably informative error title and message.

Parameters
  • exc (OSError) – Original OSError.

  • dbx_path (str | None) – Dropbox path associated with the error.

  • local_path (str | None) – Local path associated with the error.

Returns

Converted exception.

Return type

LocalError

maestral.errorhandling.dropbox_to_maestral_error(exc, dbx_path=None, local_path=None)[source]

Converts a Dropbox SDK exception to a maestral.exceptions.MaestralApiError and tries to add a reasonably informative error title and message.

Parameters
  • exc (exceptions.DropboxException | ValidationError | requests.HTTPError) – Dropbox SDK exception..

  • dbx_path (str | None) – Dropbox path associated with the error.

  • local_path (str | None) – Local path associated with the error.

Returns

Converted exception.

Return type

maestral.exceptions.MaestralApiError

maestral.errorhandling.retry_on_error(error_cls, max_retries, backoff=0, msg_regex=None)[source]

A decorator to retry a function call if a specified exception occurs.

Parameters
  • error_cls (type[Exception]) – Error type to catch.

  • max_retries (int) – Maximum number of retries.

  • msg_regex (str | None) – If provided, retry errors only if the regex matches the error message. Matches are found with re.search().

  • backoff (int) – Time in seconds to sleep before retry.

Return type

Callable[[FT], FT]