summaryrefslogtreecommitdiff
path: root/lib/ovsdb-error.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-03-09 12:41:37 -0800
committerBen Pfaff <blp@nicira.com>2011-03-10 11:23:59 -0800
commit1dd5b71d14b5c5360f97071041ec1bdd1f8d2445 (patch)
treef30031c2ba81acc9d48b880bdc965530cd493734 /lib/ovsdb-error.c
parentd198c4beee03741670d046baf0179ac5583305bb (diff)
downloadopenvswitch-1dd5b71d14b5c5360f97071041ec1bdd1f8d2445.tar.gz
ovsdb: Improve error reporting for some internal errors.
Sometimes internal errors are generated based on an originating error. In these cases we were just throwing this information away. This commit adds this information to the internal error report so that the error will be easier to track down. I haven't actually seen a situation like this come up.
Diffstat (limited to 'lib/ovsdb-error.c')
-rw-r--r--lib/ovsdb-error.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/ovsdb-error.c b/lib/ovsdb-error.c
index d6b4576ea..3b90b1616 100644
--- a/lib/ovsdb-error.c
+++ b/lib/ovsdb-error.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -114,8 +114,16 @@ ovsdb_wrap_error(struct ovsdb_error *error, const char *details, ...)
return error;
}
+/* Returns an ovsdb_error that represents an internal error for file name
+ * 'file' and line number 'line', with 'details' (formatted as with printf())
+ * as the associated message. The caller is responsible for freeing the
+ * returned error.
+ *
+ * If 'inner_error' is nonnull then the returned error is wrapped around
+ * 'inner_error'. Takes ownership of 'inner_error'. */
struct ovsdb_error *
-ovsdb_internal_error(const char *file, int line, const char *details, ...)
+ovsdb_internal_error(struct ovsdb_error *inner_error,
+ const char *file, int line, const char *details, ...)
{
struct ds ds = DS_EMPTY_INITIALIZER;
struct backtrace backtrace;
@@ -144,6 +152,14 @@ ovsdb_internal_error(const char *file, int line, const char *details, ...)
ds_put_format(&ds, " (%s %s%s)", program_name, VERSION, BUILDNR);
+ if (inner_error) {
+ char *s = ovsdb_error_to_string(inner_error);
+ ds_put_format(&ds, " (generated from: %s)", s);
+ free(s);
+
+ ovsdb_error_destroy(inner_error);
+ }
+
error = ovsdb_error("internal error", "%s", ds_cstr(&ds));
ds_destroy(&ds);