From: Remi Gacogne Date: Thu, 16 Jul 2026 07:13:03 +0000 (+0200) Subject: dnsdist: Properly handle PDNSException in our Rust library X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bdaefaed654969097d9da310c69f6d9c9157fb33;p=thirdparty%2Fpdns.git dnsdist: Properly handle PDNSException in our Rust library Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist-rust-bridge.hh b/pdns/dnsdistdist/dnsdist-rust-bridge.hh index dac2511f5f..ea1ea01257 100644 --- a/pdns/dnsdistdist/dnsdist-rust-bridge.hh +++ b/pdns/dnsdistdist/dnsdist-rust-bridge.hh @@ -9,6 +9,32 @@ class DNSRule; #include "rust/cxx.h" +/* the following replaces the default handling of exceptions + thrown from C++ code called from Rust. It is necessary because + some of our legacy code uses the special PDNSException that does + not inherit from std::exception +*/ +#include "pdnsexception.hh" + +namespace rust::behavior +{ + +template +static void trycatch(Try &&func, Fail &&fail) noexcept +{ + try { + func(); + } + catch (const std::exception& exp) { + fail(exp.what()); + } + catch (const PDNSException& exp) { + fail(exp.reason); + } +} + +} + namespace dnsdist::rust::settings {