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.
This commit is contained in:
John Ralls 2015-07-27 15:59:12 -07:00
parent d2798b8c3f
commit 3ccaec6e38
5 changed files with 27 additions and 13 deletions

View File

@ -1685,7 +1685,7 @@ gnc_dbi_safe_sync_all( QofBackend *qbe, QofBook *book )
be->primary_book = book; be->primary_book = book;
gnc_sql_sync_all( &be->sql_be, 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, conn_table_operation( (GncSqlConnection*)conn, table_list,
rollback ); rollback );

View File

@ -512,7 +512,8 @@ gnc_sql_sync_all( GncSqlBackend* be, /*@ dependent @*/ QofBook *book )
} }
else 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 ); is_ok = gnc_sql_connection_rollback_transaction( be->conn );
} }
finish_progress( be ); finish_progress( be );

View File

@ -1033,7 +1033,7 @@ write_book(FILE *out, QofBook *book, sixtp_gdv2 *gd)
g_list_length(gnc_book_get_schedxactions(book)->sx_list), g_list_length(gnc_book_get_schedxactions(book)->sx_list),
"budget", qof_collection_count( "budget", qof_collection_count(
qof_book_get_collection(book, GNC_ID_BUDGET)), 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)) NULL))
return FALSE; 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. /* 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 We do it this way instead of just calling xmlElemDump so that we can
increment the progress bar as we go. */ 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) xmlGetProp(parent, BAD_CAST "version")) < 0)
return FALSE; return FALSE;
/* We create our own output buffer so we can call xmlNodeDumpOutput to get /* We create our own output buffer so we can call xmlNodeDumpOutput to get
the indendation correct. */ the indendation correct. */
outbuf = xmlOutputBufferCreateFile(out, NULL); outbuf = xmlOutputBufferCreateFile(out, NULL);
@ -1144,7 +1144,7 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd)
xmlFreeNode(parent); xmlFreeNode(parent);
return FALSE; return FALSE;
} }
for (node = parent->children; node; node = node->next) for (node = parent->children; node; node = node->next)
{ {
/* Write two spaces since xmlNodeDumpOutput doesn't indent the first line */ /* 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); xmlNodeDumpOutput(outbuf, NULL, node, 1, 1, NULL);
/* It also doesn't terminate the last line */ /* It also doesn't terminate the last line */
xmlOutputBufferWrite(outbuf, 1, "\n"); xmlOutputBufferWrite(outbuf, 1, "\n");
if (ferror(out)) if (ferror(out))
break; break;
gd->counter.prices_loaded += 1; gd->counter.prices_loaded += 1;
run_callback(gd, "prices"); run_callback(gd, "prices");
} }
xmlOutputBufferClose(outbuf); xmlOutputBufferClose(outbuf);
if (ferror(out) || fprintf(out, "</%s>\n", parent->name) < 0) if (ferror(out) || fprintf(out, "</%s>\n", parent->name) < 0)
{ {
xmlFreeNode(parent); xmlFreeNode(parent);
@ -1670,8 +1670,7 @@ gnc_book_write_accounts_to_xml_file_v2(
if (out && fclose(out)) if (out && fclose(out))
success = FALSE; success = FALSE;
if (!success if (!success && !qof_backend_check_error(be))
&& qof_backend_get_error(be) == ERR_BACKEND_NO_ERR)
{ {
/* Use a generic write error code */ /* Use a generic write error code */
@ -2186,4 +2185,3 @@ gnc_xml2_parse_with_subst (FileBackend *fbe, QofBook *book, GHashTable *subst)
return success; return success;
} }

View File

@ -64,6 +64,13 @@ qof_backend_get_error (QofBackend *be)
return err; 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 void
qof_backend_set_message (QofBackend *be, const char *format, ...) qof_backend_set_message (QofBackend *be, const char *format, ...)
{ {

View File

@ -166,6 +166,14 @@ void qof_backend_set_error (QofBackend *be, QofBackendError err);
*/ */
QofBackendError qof_backend_get_error (QofBackend *be); 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. /** \brief Load a QOF-compatible backend shared library.