diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2016-11-15 14:41:13 -0600 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2016-11-17 15:36:21 -0600 |
| commit | ea2414476d1a278a010265825d718624125cbb56 (patch) | |
| tree | 26d16ddd5f88a1fa614927f63d9e3e396fc33a38 | |
| parent | 4a5c3b307cbbae9a462b8ba40a034f91fdef9dfd (diff) | |
| download | sdbusplus-ea2414476d1a278a010265825d718624125cbb56.tar.gz sdbusplus-ea2414476d1a278a010265825d718624125cbb56.zip | |
sdbus++: enhance exception information
Use both 'name' and 'description' for exceptions. All sdbusplus
exceptions now have a 'name()' and 'description()' method which
give the dbus error name and a human-readable description
respectively. The standard 'what' is now '<name>: <description>'.
Change-Id: Ic6cdb88350c07589cbfbf233e84a575632383af6
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
| -rw-r--r-- | sdbusplus/exception.hpp | 2 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/error.mako.cpp | 10 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/error.mako.hpp | 10 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/method.mako.prototype.hpp | 6 |
4 files changed, 20 insertions, 8 deletions
diff --git a/sdbusplus/exception.hpp b/sdbusplus/exception.hpp index 01687a4..f5f6ab6 100644 --- a/sdbusplus/exception.hpp +++ b/sdbusplus/exception.hpp @@ -12,6 +12,8 @@ namespace exception * by the bindings. */ struct exception : public std::exception { + virtual const char* name() const noexcept = 0; + virtual const char* description() const noexcept = 0; }; /** base exception class for all errors generated by sdbusplus itself. */ diff --git a/tools/sdbusplus/templates/error.mako.cpp b/tools/sdbusplus/templates/error.mako.cpp index 62cc541..74cefdc 100644 --- a/tools/sdbusplus/templates/error.mako.cpp +++ b/tools/sdbusplus/templates/error.mako.cpp @@ -9,9 +9,17 @@ namespace ${s} namespace Error { % for e in error.errors: +const char* ${e.name}::name() const noexcept +{ + return errName; +} +const char* ${e.name}::description() const noexcept +{ + return errDesc; +} const char* ${e.name}::what() const noexcept { - return name; + return errWhat; } % endfor diff --git a/tools/sdbusplus/templates/error.mako.hpp b/tools/sdbusplus/templates/error.mako.hpp index 51f4860..2f34882 100644 --- a/tools/sdbusplus/templates/error.mako.hpp +++ b/tools/sdbusplus/templates/error.mako.hpp @@ -12,12 +12,16 @@ namespace Error { % for e in error.errors: -struct ${e.name} : public sdbusplus::exception_t +struct ${e.name} final : public sdbusplus::exception_t { - static constexpr auto name = "${error.name}.${e.name}"; - static constexpr auto description = + static constexpr auto errName = "${error.name}.${e.name}"; + static constexpr auto errDesc = "${e.description.strip()}"; + static constexpr auto errWhat = + "${error.name}.${e.name}: ${e.description.strip()}"; + const char* name() const noexcept override; + const char* description() const noexcept override; const char* what() const noexcept override; }; diff --git a/tools/sdbusplus/templates/method.mako.prototype.hpp b/tools/sdbusplus/templates/method.mako.prototype.hpp index d9c1ec7..090ac55 100644 --- a/tools/sdbusplus/templates/method.mako.prototype.hpp +++ b/tools/sdbusplus/templates/method.mako.prototype.hpp @@ -137,15 +137,13 @@ int ${interface_name()}::_callback_${ method.CamelCase }( } catch(sdbusplus::internal_exception_t& e) { - auto name = e.what(); - sd_bus_error_set_const(error, name, name); + sd_bus_error_set_const(error, e.name(), e.description()); return -EINVAL; } % for e in method.errors: catch(sdbusplus::${error_namespace(e)}::${error_name(e)}& e) { - auto name = e.what(); - sd_bus_error_set_const(error, name, name); + sd_bus_error_set_const(error, e.name(), e.description()); return -EINVAL; } % endfor |

