Skip to content

Commit

Permalink
Add the API function that failed to the message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmmv committed Jul 7, 2015
1 parent 9df5d27 commit a5b7ab2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion utils/sqlite/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
{
}
Expand Down
9 changes: 6 additions & 3 deletions utils/sqlite/exceptions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand Down

0 comments on commit a5b7ab2

Please sign in to comment.