mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
d2798b8c3f
commit
3ccaec6e38
@ -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 );
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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, ...)
|
||||
{
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user