]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Properly handle PDNSException in our Rust library
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Jul 2026 07:13:03 +0000 (09:13 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Jul 2026 07:13:03 +0000 (09:13 +0200)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-rust-bridge.hh

index dac2511f5fed75b8467c094884e49435531ae943..ea1ea01257f437b986c85cb041edd077e40b82dd 100644 (file)
@@ -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 <typename Try, typename Fail>
+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
 {