gnucash maint: Make backend sync errors survive to the session.

John Ralls jralls at code.gnucash.org
Mon Jul 27 19:04:47 EDT 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/3ccaec6e (commit)
	from  https://github.com/Gnucash/gnucash/commit/d2798b8c (commit)



commit 3ccaec6e381843b5e7f5ac03f199fc27fb9de2a4
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Jul 27 15:59:12 2015 -0700

    Make backend sync errors survive to the session.
    
    The backends were using qof_backend_get_error() to test for sync errors.
    This function clears the error, so the tests resulted in the error being
    cleared before the session could see it and so it thought that the sync
    had succeeded.
    
    Replace those uses of qof_backend_get_error() with a new function
    qof_backend_check_error() that doesn't clear the error.

diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c
index 6733de3..79b7116 100644
--- a/src/backend/dbi/gnc-backend-dbi.c
+++ b/src/backend/dbi/gnc-backend-dbi.c
@@ -1685,7 +1685,7 @@ gnc_dbi_safe_sync_all( QofBackend *qbe, QofBook *book )
     be->primary_book = book;
 
     gnc_sql_sync_all( &be->sql_be, book );
-    if ( ERR_BACKEND_NO_ERR != qof_backend_get_error( qbe ) )
+    if (qof_backend_check_error (qbe))
     {
         conn_table_operation( (GncSqlConnection*)conn, table_list,
                               rollback );
diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c
index dc819db..6140637 100644
--- a/src/backend/sql/gnc-backend-sql.c
+++ b/src/backend/sql/gnc-backend-sql.c
@@ -512,7 +512,8 @@ gnc_sql_sync_all( GncSqlBackend* be, /*@ dependent @*/ QofBook *book )
     }
     else
     {
-        qof_backend_set_error( (QofBackend*)be, ERR_BACKEND_SERVER_ERR );
+        if (!qof_backend_check_error ((QofBackend*)be))
+            qof_backend_set_error( (QofBackend*)be, ERR_BACKEND_SERVER_ERR );
         is_ok = gnc_sql_connection_rollback_transaction( be->conn );
     }
     finish_progress( be );
diff --git a/src/backend/xml/io-gncxml-v2.c b/src/backend/xml/io-gncxml-v2.c
index c7ab52e..051c94c 100644
--- a/src/backend/xml/io-gncxml-v2.c
+++ b/src/backend/xml/io-gncxml-v2.c
@@ -1033,7 +1033,7 @@ write_book(FILE *out, QofBook *book, sixtp_gdv2 *gd)
                       g_list_length(gnc_book_get_schedxactions(book)->sx_list),
                       "budget", qof_collection_count(
                           qof_book_get_collection(book, GNC_ID_BUDGET)),
-                      "price", gnc_pricedb_get_num_prices(gnc_pricedb_get_db(book)), 
+                      "price", gnc_pricedb_get_num_prices(gnc_pricedb_get_db(book)),
                       NULL))
         return FALSE;
 
@@ -1131,11 +1131,11 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd)
     /* Write out the parent pricedb tag then loop to write out each price.
        We do it this way instead of just calling xmlElemDump so that we can
        increment the progress bar as we go. */
-       
-    if (fprintf( out, "<%s version=\"%s\">\n", parent->name, 
+
+    if (fprintf( out, "<%s version=\"%s\">\n", parent->name,
                  xmlGetProp(parent, BAD_CAST "version")) < 0)
         return FALSE;
-        
+
     /* We create our own output buffer so we can call xmlNodeDumpOutput to get
        the indendation correct. */
     outbuf = xmlOutputBufferCreateFile(out, NULL);
@@ -1144,7 +1144,7 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd)
         xmlFreeNode(parent);
         return FALSE;
     }
-       
+
     for (node = parent->children; node; node = node->next)
     {
         /* Write two spaces since xmlNodeDumpOutput doesn't indent the first line */
@@ -1152,14 +1152,14 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd)
         xmlNodeDumpOutput(outbuf, NULL, node, 1, 1, NULL);
         /* It also doesn't terminate the last line */
         xmlOutputBufferWrite(outbuf, 1, "\n");
-        if (ferror(out)) 
+        if (ferror(out))
             break;
         gd->counter.prices_loaded += 1;
         run_callback(gd, "prices");
     }
-    
+
     xmlOutputBufferClose(outbuf);
-    
+
     if (ferror(out) || fprintf(out, "</%s>\n", parent->name) < 0)
     {
         xmlFreeNode(parent);
@@ -1670,8 +1670,7 @@ gnc_book_write_accounts_to_xml_file_v2(
     if (out && fclose(out))
         success = FALSE;
 
-    if (!success
-            && qof_backend_get_error(be) == ERR_BACKEND_NO_ERR)
+    if (!success && !qof_backend_check_error(be))
     {
 
         /* Use a generic write error code */
@@ -2186,4 +2185,3 @@ gnc_xml2_parse_with_subst (FileBackend *fbe, QofBook *book, GHashTable *subst)
 
     return success;
 }
-
diff --git a/src/libqof/qof/qofbackend.c b/src/libqof/qof/qofbackend.c
index 6a8ab60..07dfab0 100644
--- a/src/libqof/qof/qofbackend.c
+++ b/src/libqof/qof/qofbackend.c
@@ -64,6 +64,13 @@ qof_backend_get_error (QofBackend *be)
     return err;
 }
 
+gboolean
+qof_backend_check_error (QofBackend *be)
+{
+    g_return_val_if_fail (be != NULL, TRUE);
+    return be->last_err != ERR_BACKEND_NO_ERR;
+}
+
 void
 qof_backend_set_message (QofBackend *be, const char *format, ...)
 {
diff --git a/src/libqof/qof/qofbackend.h b/src/libqof/qof/qofbackend.h
index 13aed89..5b4e411 100644
--- a/src/libqof/qof/qofbackend.h
+++ b/src/libqof/qof/qofbackend.h
@@ -166,6 +166,14 @@ void qof_backend_set_error (QofBackend *be, QofBackendError err);
  */
 QofBackendError qof_backend_get_error (QofBackend *be);
 
+/** Report if the backend is in an error state.
+ *  Since get_error resets the error state, its use for branching as the backend
+ *  bubbles back up to the session would make the session think that there was
+ *  no error.
+ * \param be The backend being tested.
+ * \return TRUE if the backend has an error set.
+ */
+gboolean qof_backend_check_error (QofBackend *be);
 
 /** \brief Load a QOF-compatible backend shared library.
 



Summary of changes:
 src/backend/dbi/gnc-backend-dbi.c |  2 +-
 src/backend/sql/gnc-backend-sql.c |  3 ++-
 src/backend/xml/io-gncxml-v2.c    | 20 +++++++++-----------
 src/libqof/qof/qofbackend.c       |  7 +++++++
 src/libqof/qof/qofbackend.h       |  8 ++++++++
 5 files changed, 27 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list