Skip to content
Snippets Groups Projects

DOC: Update tutorial on error handling

Merged Florian Spreckelsen requested to merge f-doc-errors into dev
1 unresolved thread
Files
2
+ 49
13
Error Handling
--------------
==============
HeartDBException
~~~~~~~~~~~~~~~~
In case of erroneous transactions, connection problems and a lot of
other cases, PyCaosDB may raise specific errors in order to pinpoint
the problem as precisely as possible. Some of these errors a
representations of errors in the CaosDB server, others stem from
problems that occurred on the client side.
The errors and exceptions are ordered hierarchically form the most
general exceptions to specific transaction or connection problems. The
most important error types and the hierarchy will be explained in the
following. For more information on specific error types, see also the
`source code
<https://docs.indiscale.com/caosdb-pylib/_apidoc/caosdb.html#module-caosdb.exceptions>`_.
.. note::
From PyCaosDB 0.5 and newer, the error handling has changed
significantly. New error classes have been introduced and the
behavior of ``TransactionError`` and ``EntityError`` has been
re-worked. In the following, only the "new" errors are
discussed. Please refer to the documentation of PyCaosDB 0.4.1 and
earlier for the old error handling.
CaosDBException
----------------
This is the most generic exception and all other error classes inherit
from this one. Because of its generality, it doesn't tell you much
except that some component of PyCaosDB raised an exception. If you
want to catch all possible CaosDB errors, this is the class to use.
TransactionError
~~~~~~~~~~~~~~~~
----------------
Every transaction (calling ``insert``, ``update``, ``retrieve``, or
``delete`` on a container or an entity) may finish with errors. They
indicate, for instance, that an entity does not exist or that you need
to specify a data type for your property and much more. If and only if
one or more errors occur during a transaction a ``TransactionError``
will be raised by the transaction method. The ``TransactionError`` class
is a container for all errors which occur during a transaction. It can
help you to find the crucial problems with your transaction by two
important methods: \* ``get_errors()`` which returns a list of instances
of ``EntityError``. \* ``get_entities()`` which returns a list of
entities in the transaction container which are erroneous.
Additionally, ``print(transaction_error`` prints a tree-like
will be raised by the transaction method. The ``TransactionError``
class is a container for all errors which occur during a
transaction. It usually contains one or more :ref:`entity
errors<EntityError>` which you can inspect in order to learn why the
transaction failed. For this inspection, there are some helpful
attributes and methods provided by the ``TransactionError``:
* ``entities``: a set of all entities that caused at least one error
in this transaction
* ``errors``: a set of all ``EntityError`` objects that occurred during
the transaction.
* ``has_error(error_t)``: Check whether an error of type ``error_t``
occurred during the transaction.
Additionally, ``print(transaction_error)`` prints a tree-like
representation of all errors regarding the transaction in question.
EntityError
~~~~~~~~~~~
-----------
An ``EntityError`` represents a single error that has been returned by
the server. You might call \* ``get_entity()`` which returns the entity
Loading