pyuno/qa/pytests/embindtest.py           |   15 ++++++++++++++-
 pyuno/source/module/pyuno_runtime.cxx    |   18 ++++++++++++++++++
 unotest/source/embindtest/embindtest.cxx |    4 ++--
 3 files changed, 34 insertions(+), 3 deletions(-)

New commits:
commit 7bdd020783f099069e7a0f11e89f8ecdef5985e3
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Tue Dec 9 23:33:08 2025 +0100
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Wed Dec 10 07:58:18 2025 +0100

    Fix any2PyObject mapping of UNO exceptions
    
    That
    
    >             // the exception base functions want to have an "args" tuple,
    >             // which contains the message
    
    code is there ever since e80bdbafeba9af9b58aac81b999f4b299c9eecd6 "initial
    checkin for the pyuno-0.9.2 release" for reasons that are not clear to me, 
but
    at least in the "TODO" scenarios from 
3320b5fe2e3c696f3e0f2e301c922d89108f5c12
    "Add exhaustive testing of PyUNO type mapping based on embindtest" and
    1e2e9a20a4190140e32e6996ea5fd6c22c71e55f "More exhaustive testing of PyUNO 
type
    mapping based on embindtest" (which are hereby fixed), that
    PyObject_SetAttrString would cause a Python exception, cf.
    
    > 
info:pyuno.runtime:1489432:1489432:pyuno/source/module/pyuno_runtime.cxx:533: 
setting exception args raised Python exception <class 'AttributeError'>: 
AttributeError('args')
    
    so at least catch that.  (And maybe that code is obsolete anyway it would 
make
    even more sense to drop it altogether.)
    
    Change-Id: Ic651d106f34e0b316cba59ae66d2402b8f86b0f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195340
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/pyuno/qa/pytests/embindtest.py b/pyuno/qa/pytests/embindtest.py
index 1de36595ce1a..796e57998af3 100644
--- a/pyuno/qa/pytests/embindtest.py
+++ b/pyuno/qa/pytests/embindtest.py
@@ -554,7 +554,20 @@ class EmbindTest(unittest.TestCase):
                         test)),)))
             #TODO: direct call?
 
-        #TODO: v = test.getAnyException()
+        v = test.getAnyException()
+        self.assertTrue(v.Message.startswith('error')) #TODO: use Python 3.14 
assertStartsWith
+        self.assertEqual(v.Context, None)
+        self.assertEqual(v.m1, -123456)
+        self.assertEqual(v.m2, 100.5)
+        self.assertEqual(v.m3, 'hä')
+        self.assertTrue(test.isAnyException(v))
+        self.assertTrue(
+            uno.invoke(
+                test, 'isAnyException',
+                (uno.Any(
+                    'org.libreoffice.embindtest.Exception',
+                    Exception('error', None, -123456, 100.5, 'hä')),)))
+            #TODO: direct call?
 
         v = test.getAnyInterface()
         self.assertEqual(v, test)
diff --git a/pyuno/source/module/pyuno_runtime.cxx 
b/pyuno/source/module/pyuno_runtime.cxx
index 85bbc5039a67..5840b249618f 100644
--- a/pyuno/source/module/pyuno_runtime.cxx
+++ b/pyuno/source/module/pyuno_runtime.cxx
@@ -516,6 +516,24 @@ PyRef Runtime::any2PyObject (const Any &a ) const
             // the exception base functions want to have an "args" tuple,
             // which contains the message
             PyObject_SetAttrString( ret.get(), "args", args.get() );
+            PyRef excType, excValue, excTraceback;
+            PyErr_Fetch(
+                reinterpret_cast<PyObject **>(&excType), 
reinterpret_cast<PyObject **>(&excValue),
+                reinterpret_cast<PyObject **>(&excTraceback));
+#if defined SAL_LOG_INFO
+            if (excType.is()) {
+                OUString more;
+                if (excValue.is()) {
+                    PyRef valueRep(PyObject_Repr(excValue.get()), 
SAL_NO_ACQUIRE);
+                    more = ": " + pyString2ustring(valueRep.get());
+                }
+                PyRef typeRep(PyObject_Repr(excType.get()), SAL_NO_ACQUIRE);
+                SAL_INFO(
+                    "pyuno.runtime",
+                    "setting exception args raised Python exception "
+                        << pyString2ustring(typeRep.get()) << more);
+            }
+#endif
         }
         return ret;
     }
diff --git a/unotest/source/embindtest/embindtest.cxx 
b/unotest/source/embindtest/embindtest.cxx
index 4e1293951b01..8a7ccf1bbab7 100644
--- a/unotest/source/embindtest/embindtest.cxx
+++ b/unotest/source/embindtest/embindtest.cxx
@@ -396,8 +396,8 @@ void 
doExecuteTest(css::uno::Reference<org::libreoffice::embindtest::XTest> cons
     {
         auto const val = test->getAnyException();
         verify(checkAnyException(val));
-        //TODO: bool const ok = test->isAnyException(val);
-        //TODO: verify(ok);
+        bool const ok = test->isAnyException(val);
+        verify(ok);
     }
     {
         auto const val = test->getAnyInterface();

Reply via email to