X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fovsdb-error.c;h=db8019f385225e8df95bdd11a314b9bb6c80ede5;hb=ea83a2fcd0d31246ece7bdea4c54e162f432e81c;hp=c0eddf280e9d0b907ada166f49f8e4e523e0a837;hpb=f85f8ebbfac946c19b3c6eb0f4170f579d0a4d25;p=sliver-openvswitch.git diff --git a/lib/ovsdb-error.c b/lib/ovsdb-error.c index c0eddf280..db8019f38 100644 --- a/lib/ovsdb-error.c +++ b/lib/ovsdb-error.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,9 @@ #include "dynamic-string.h" #include "json.h" #include "util.h" +#include "vlog.h" + +VLOG_DEFINE_THIS_MODULE(ovsdb_error); struct ovsdb_error { const char *tag; /* String for "error" member. */ @@ -83,7 +86,7 @@ ovsdb_syntax_error(const struct json *json, const char *tag, if (json) { /* XXX this is much too much information in some cases */ - error->syntax = json_to_string(json, 0); + error->syntax = json_to_string(json, JSSF_SORT); } return error; @@ -219,3 +222,19 @@ ovsdb_error_get_tag(const struct ovsdb_error *error) { return error->tag; } + +/* If 'error' is nonnull, logs it as an error and frees it. To be used in + * situations where an error should never occur, but an 'ovsdb_error *' gets + * passed back anyhow. */ +void +ovsdb_error_assert(struct ovsdb_error *error) +{ + if (error) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); + char *s = ovsdb_error_to_string(error); + VLOG_ERR_RL(&rl, "unexpected ovsdb error: %s", s); + free(s); + ovsdb_error_destroy(error); + } +} +