From a5b7ab2f787a8ce591aab3b02d8a1c0b10ba09d2 Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Tue, 7 Jul 2015 16:07:43 -0400 Subject: [PATCH] Add the API function that failed to the message The sqlite::api_error class took the name of the API function that caused the error as a parameter but did not add such information to the error message. I probably assumed that the message returned by the sqlite API would be descriptive enough, but isn't. Add the details now. --- utils/sqlite/exceptions.cpp | 2 +- utils/sqlite/exceptions_test.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/sqlite/exceptions.cpp b/utils/sqlite/exceptions.cpp index 79443bc0..222299b4 100644 --- a/utils/sqlite/exceptions.cpp +++ b/utils/sqlite/exceptions.cpp @@ -106,7 +106,7 @@ sqlite::error::db_filename(void) const sqlite::api_error::api_error(const optional< fs::path >& db_filename_, const std::string& api_function_, const std::string& message_) : - error(db_filename_, message_), + error(db_filename_, F("%s (sqlite op: %s)") % message_ % api_function_), _api_function(api_function_) { } diff --git a/utils/sqlite/exceptions_test.cpp b/utils/sqlite/exceptions_test.cpp index 74b45d07..27d62c54 100644 --- a/utils/sqlite/exceptions_test.cpp +++ b/utils/sqlite/exceptions_test.cpp @@ -74,7 +74,9 @@ ATF_TEST_CASE_WITHOUT_HEAD(api_error__explicit); ATF_TEST_CASE_BODY(api_error__explicit) { const sqlite::api_error e(none, "some_function", "Some text"); - ATF_REQUIRE_EQ("Some text (sqlite db: in-memory)", std::string(e.what())); + ATF_REQUIRE_EQ( + "Some text (sqlite op: some_function) (sqlite db: in-memory)", + std::string(e.what())); ATF_REQUIRE_EQ("some_function", e.api_function()); } @@ -96,8 +98,9 @@ ATF_TEST_CASE_BODY(api_error__from_database) const sqlite::api_error e = sqlite::api_error::from_database( db, "real_function"); - ATF_REQUIRE_MATCH(".*ABCDE.*\\(sqlite db: .*/test.db\\)", - std::string(e.what())); + ATF_REQUIRE_MATCH( + ".*ABCDE.*\\(sqlite op: real_function\\) \\(sqlite db: .*/test.db\\)", + std::string(e.what())); ATF_REQUIRE_EQ("real_function", e.api_function()); }