summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2011-08-20 17:14:24 +0200
committerLionel Elie Mamane <lionel@mamane.lu>2011-08-21 01:46:07 +0200
commitfa43b7742227a74c2bfb83c5147ac6eb69e7ef20 (patch)
treee772958252373703c4cc5c1e3e510533c0bed703 /pyuno
parent41a68a4f77a639def35d778b86b6aeda8fe60a7b (diff)
pyuno: make extractUnoException handle exceptions raised by uno.py loading
This allows having a meaningful error message when extractUnoException is called from pyuno_loader::getLoaderModule() (via raiseRuntimeExceptionWhenNeeded()). If it is called to treat an error that cropped up in loading uno.py, the old code would abort the whole operation by throwing an exception because... it gets essentially the same error. The new code leads to a sensible message on the Python debug console.
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/source/module/pyuno_runtime.cxx45
1 files changed, 31 insertions, 14 deletions
diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx
index 61d05d8321f5..0e339f0cad8e 100644
--- a/pyuno/source/module/pyuno_runtime.cxx
+++ b/pyuno/source/module/pyuno_runtime.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; eval:(c-set-style "bsd"); tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -53,6 +53,7 @@ using com::sun::star::uno::TypeDescription;
using com::sun::star::uno::Sequence;
using com::sun::star::uno::Type;
using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::Exception;
using com::sun::star::uno::RuntimeException;
using com::sun::star::uno::XComponentContext;
using com::sun::star::lang::XSingleServiceFactory;
@@ -914,41 +915,56 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
Any Runtime::extractUnoException( const PyRef & excType, const PyRef &excValue, const PyRef &excTraceback) const
{
- PyRef str;
+ OUString str;
Any ret;
if( excTraceback.is() )
{
- PyRef unoModule( impl ? impl->cargo->getUnoModule() : 0 );
+ Exception e;
+ PyRef unoModule;
+ if ( impl )
+ {
+ try
+ {
+ unoModule = impl->cargo->getUnoModule();
+ }
+ catch (Exception ei)
+ {
+ e=ei;
+ }
+ }
if( unoModule.is() )
{
PyRef extractTraceback(
PyDict_GetItemString(unoModule.get(),"_uno_extract_printable_stacktrace" ) );
- if( extractTraceback.is() )
+ if( PyCallable_Check(extractTraceback.get()) )
{
PyRef args( PyTuple_New( 1), SAL_NO_ACQUIRE );
PyTuple_SetItem( args.get(), 0, excTraceback.getAcquired() );
- str = PyRef( PyObject_CallObject( extractTraceback.get(),args.get() ), SAL_NO_ACQUIRE);
+ PyRef pyStr( PyObject_CallObject( extractTraceback.get(),args.get() ), SAL_NO_ACQUIRE);
+ str = rtl::OUString::createFromAscii( PyString_AsString(pyStr.get()) );
}
else
{
- str = PyRef(
- PyString_FromString( "Couldn't find uno._uno_extract_printable_stacktrace" ),
- SAL_NO_ACQUIRE );
+ str = OUString(RTL_CONSTASCII_USTRINGPARAM("Couldn't find uno._uno_extract_printable_stacktrace"));
}
}
else
{
- str = PyRef(
- PyString_FromString( "Couldn't find uno.py, no stacktrace available" ),
- SAL_NO_ACQUIRE );
+ str = OUString(RTL_CONSTASCII_USTRINGPARAM("Could not load uno.py, no stacktrace available"));
+ if ( e.Message.getLength() > 0 )
+ {
+ str += OUString (RTL_CONSTASCII_USTRINGPARAM(" (Error loading uno.py: "));
+ str += e.Message;
+ str += OUString (RTL_CONSTASCII_USTRINGPARAM(")"));
+ }
}
}
else
{
// it may occur, that no traceback is given (e.g. only native code below)
- str = PyRef( PyString_FromString( "no traceback available" ), SAL_NO_ACQUIRE);
+ str = OUString( RTL_CONSTASCII_USTRINGPARAM( "no traceback available" ) );
}
if( isInstanceOfStructOrException( excValue.get() ) )
@@ -978,9 +994,10 @@ Any Runtime::extractUnoException( const PyRef & excType, const PyRef &excValue,
buf.appendAscii( "Couldn't convert exception value to a string" );
}
buf.appendAscii( ", traceback follows\n" );
- if( str.is() )
+ if( str.getLength() > 0 )
{
- buf.appendAscii( PyString_AsString( str.get() ) );
+ buf.append( str );
+ buf.appendAscii( "\n" );
}
else
{