BritishGeologicalSurvey / etlhelper

ETL Helper is a Python ETL library to simplify data transfer into and out of databases.
https://britishgeologicalsurvey.github.io/etlhelper/
GNU Lesser General Public License v3.0
100 stars 25 forks source link

Make query SQL, error message, database type and paramstyle attributes of ETLHelperQueryErrors #191

Open volcan01010 opened 3 months ago

volcan01010 commented 3 months ago

Summary

As an ETL Helper user, I want access to the individual parameters of a query error, so that I can further process them.

Description

We currently have ETLHelperQueryError, ETLHelperExtractError, ETLHelperInsertError that can be thrown if there is a problem with a SQL query. In each case where they are used, they are supplied with a message constructed as follows:

            msg = (f"SQL query raised an error.\n\n{select_query}\n\n"
                   f"Required paramstyle: {helper.paramstyle}\n\n{exc}\n")
            raise ETLHelperExtractError(msg)

The message is helpful, however the individual parameters are not accessible.

The ETLHelperQueryError should take the query, the database_error_message and the helper as parameters. It should store the first two as attributes, and extract the paramstyle and database type from the helper and store those as attributes, too. They can then be accessed for further processing.

The repr or str of the class should be modified so that it appears as an error message similar to:

Error executing SQL query against _sqlite_ database with paramstyle _qmark_.
Query:

  SELECT * FROM hello

Error message from database:

  bad table

ExtractError and InsertError should be subclasses of QueryError, so that they inherit the same behaviour.

Acceptance criteria