aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-25 08:53:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-25 08:53:16 +0200
commit5f0b5d9110499effb86be12d8f6d74eddd27d111 (patch)
tree00494c0269864510085fbca7bd4b3d7d81a3703f
parentd28d7cabb0896a93edf33123b1e83f4af632e5e5 (diff)
Get rid of trailing newlines in error messages
-rw-r--r--odb/pgsql/error.cxx32
1 files changed, 18 insertions, 14 deletions
diff --git a/odb/pgsql/error.cxx b/odb/pgsql/error.cxx
index c91a9dc..c7a7833 100644
--- a/odb/pgsql/error.cxx
+++ b/odb/pgsql/error.cxx
@@ -29,40 +29,44 @@ namespace odb
throw bad_alloc ();
}
- const char* error_message (PQresultErrorMessage (r));
+ string msg;
+ {
+ // Can be NULL in case of PGRES_BAD_RESPONSE.
+ //
+ const char* m (PQresultErrorMessage (r));
+ msg = (m != 0 ? m : "bad server response");
+
+ // Get rid of a trailing newline if there is one.
+ //
+ string::size_type n (msg.size ());
+ if (n != 0 && msg[n - 1] == '\n')
+ msg.resize (n - 1);
+ }
switch (PQresultStatus (r))
{
case PGRES_BAD_RESPONSE:
{
- if (error_message != 0)
- throw database_exception (error_message);
- else
- throw database_exception ("bad server response");
+ throw database_exception (msg);
}
-
case PGRES_FATAL_ERROR:
{
- const char* ss (PQresultErrorField (r, PG_DIAG_SQLSTATE));
-
- assert (ss);
- assert (error_message);
+ string ss (PQresultErrorField (r, PG_DIAG_SQLSTATE));
// Deadlock detected.
//
- if (std::string ("40P01") == ss)
+ if (ss == "40P01")
throw deadlock ();
-
else if (CONNECTION_BAD == PQstatus (c.handle ()))
{
c.mark_failed ();
throw connection_lost ();
}
else
- throw database_exception (ss, error_message);
+ throw database_exception (ss, msg);
}
default:
- assert (0);
+ assert (false);
break;
}
}