From 183debd7e078d2daef38170afc8542a4e625602c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 15 Feb 2019 10:44:08 +0200 Subject: pretty up logging of exceptions Add exceptionToString() and getCaughtExceptionAsString() methods in tools. Use the new methods in DbgUnhandledException() Add special-case case code for most of the exceptions that contain extra fields, so all of the relevant data ends up in the log Change-Id: I376f6549b4d7bd480202f8bff17a454657c75ece Reviewed-on: https://gerrit.libreoffice.org/67857 Tested-by: Jenkins Reviewed-by: Noel Grandin --- tools/Library_tl.mk | 1 + tools/source/debug/debug.cxx | 356 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 319 insertions(+), 38 deletions(-) (limited to 'tools') diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index acd007cc4761..d6705d0b5925 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -37,6 +37,7 @@ $(eval $(call gb_Library_use_libraries,tl,\ comphelper \ i18nlangtag \ cppu \ + cppuhelper \ sal \ )) diff --git a/tools/source/debug/debug.cxx b/tools/source/debug/debug.cxx index 9f32eab3267c..efecd0f5027b 100644 --- a/tools/source/debug/debug.cxx +++ b/tools/source/debug/debug.cxx @@ -29,7 +29,33 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -79,55 +105,309 @@ void DbgTestSolarMutex() #endif -void DbgUnhandledException(const css::uno::Any & caught, const char* currentFunction, const char* fileAndLineNo, - const char* area, const char* explanatory) +OString exceptionToString(const css::uno::Any & caught) { - OString sMessage( "DBG_UNHANDLED_EXCEPTION in " ); - sMessage += currentFunction; - if (explanatory) + auto toOString = [](OUString const & s) { + return OUStringToOString( s, osl_getThreadTextEncoding() ); + }; + OString sMessage = toOString(caught.getValueTypeName()); + css::uno::Exception exception; + caught >>= exception; + if ( !exception.Message.isEmpty() ) + { + sMessage += " message: "; + sMessage += toOString(exception.Message); + } + if ( exception.Context.is() ) + { + const char* pContext = typeid( *exception.Context.get() ).name(); +#if defined __GLIBCXX__ + // demangle the type name, not necessary under windows, we already get demangled names there + int status; + pContext = abi::__cxa_demangle( pContext, nullptr, nullptr, &status); +#endif + sMessage += " context: "; + sMessage += pContext; + } + { + css::configuration::CorruptedConfigurationException specialized; + if ( caught >>= specialized ) { - sMessage += "\n when: "; - sMessage += explanatory; + sMessage += " details: "; + sMessage += toOString(specialized.Details); } - sMessage += "\n type: "; - sMessage += OUStringToOString( caught.getValueTypeName(), osl_getThreadTextEncoding() ); - css::uno::Exception exception; - caught >>= exception; - if ( !exception.Message.isEmpty() ) + } + { + css::configuration::InvalidBootstrapFileException specialized; + if ( caught >>= specialized ) { - sMessage += "\n message: "; - sMessage += OUStringToOString( exception.Message, osl_getThreadTextEncoding() ); + sMessage += " BootstrapFileURL: "; + sMessage += toOString(specialized.BootstrapFileURL); } - if ( exception.Context.is() ) + } + { + css::configuration::MissingBootstrapFileException specialized; + if ( caught >>= specialized ) { - const char* pContext = typeid( *exception.Context.get() ).name(); -#if defined __GLIBCXX__ - // demangle the type name, not necessary under windows, we already get demangled names there - int status; - pContext = abi::__cxa_demangle( pContext, nullptr, nullptr, &status); -#endif - sMessage += "\n context: "; - sMessage += pContext; + sMessage += " BootstrapFileURL: "; + sMessage += toOString(specialized.BootstrapFileURL); } + } + { + css::configuration::backend::MalformedDataException specialized; + if ( caught >>= specialized ) { - css::configuration::CorruptedConfigurationException - specialized; - if ( caught >>= specialized ) - { - sMessage += "\n details: "; - sMessage += OUStringToOString( - specialized.Details, osl_getThreadTextEncoding() ); - } + sMessage += "\n wrapped: "; + sMessage += exceptionToString(specialized.ErrorDetails); } + } + { + css::configuration::backend::BackendSetupException specialized; + if ( caught >>= specialized ) { - css::task::ErrorCodeIOException specialized; - if ( caught >>= specialized ) - { - sMessage += "\n details: "; - sMessage += OString::number( specialized.ErrCode ); - } + sMessage += "\n wrapped: "; + sMessage += exceptionToString(specialized.BackendException); + } + } + { + css::deployment::DependencyException specialized; + if ( caught >>= specialized ) + { + sMessage += " UnsatisfiedDependencies: "; + sMessage += toOString(comphelper::anyToString(css::uno::Any(specialized.UnsatisfiedDependencies))); + } + } + { + css::deployment::DeploymentException specialized; + if ( caught >>= specialized ) + { + sMessage += "\n wrapped: "; + sMessage += exceptionToString(specialized.Cause); + } + } + { + css::document::CorruptedFilterConfigurationException specialized; + if ( caught >>= specialized ) + { + sMessage += " Details: "; + sMessage += toOString(specialized.Details); + } + } + { + css::document::UndoFailedException specialized; + if ( caught >>= specialized ) + { + sMessage += " Reason: "; + sMessage += toOString(comphelper::anyToString(specialized.Reason)); + } + } + { + css::lang::IllegalArgumentException specialized; + if ( caught >>= specialized ) + { + sMessage += " ArgumentPosition: "; + sMessage += OString::number(specialized.ArgumentPosition); + } + } + { + css::lang::WrappedTargetException specialized; + if ( caught >>= specialized ) + { + sMessage += "\n wrapped: "; + sMessage += exceptionToString(specialized.TargetException); + } + } + { + css::lang::WrappedTargetRuntimeException specialized; + if ( caught >>= specialized ) + { + sMessage += "\n wrapped: "; + sMessage += exceptionToString(specialized.TargetException); + } + } + { + css::ldap::LdapGenericException specialized; + if ( caught >>= specialized ) + { + sMessage += " ErrorCode: "; + sMessage += OString::number(specialized.ErrorCode); + } + } + { + css::script::BasicErrorException specialized; + if ( caught >>= specialized ) + { + sMessage += " ErrorCode: "; + sMessage += OString::number(specialized.ErrorCode); + sMessage += " ErrorMessageArgument: "; + sMessage += toOString(specialized.ErrorMessageArgument); + } + } + { + css::script::CannotConvertException specialized; + if ( caught >>= specialized ) + { + sMessage += " DestinationTypeClass: "; + sMessage += toOString(comphelper::anyToString(css::uno::Any(specialized.DestinationTypeClass))); + sMessage += " Reason: "; + sMessage += OString::number(specialized.Reason); + sMessage += " ArgumentIndex: "; + sMessage += OString::number(specialized.ArgumentIndex); + } + } + { + css::script::provider::ScriptErrorRaisedException specialized; + if ( caught >>= specialized ) + { + sMessage += " scriptName: "; + sMessage += toOString(specialized.scriptName); + sMessage += " language: "; + sMessage += toOString(specialized.language); + sMessage += " lineNum: "; + sMessage += OString::number(specialized.lineNum); + } + } + { + css::script::provider::ScriptExceptionRaisedException specialized; + if ( caught >>= specialized ) + { + sMessage += " exceptionType: "; + sMessage += toOString(specialized.exceptionType); + } + } + { + css::script::provider::ScriptFrameworkErrorException specialized; + if ( caught >>= specialized ) + { + sMessage += " scriptName: "; + sMessage += toOString(specialized.scriptName); + sMessage += " language: "; + sMessage += toOString(specialized.language); + sMessage += " errorType: "; + sMessage += OString::number(specialized.errorType); + } + } + { + css::sdbc::SQLException specialized; + if ( caught >>= specialized ) + { + sMessage += " SQLState: "; + sMessage += toOString(specialized.SQLState); + sMessage += " ErrorCode: "; + sMessage += OString::number(specialized.ErrorCode); + sMessage += "\n wrapped: "; + sMessage += exceptionToString(specialized.NextException); + } + } + { + css::system::SystemShellExecuteException specialized; + if ( caught >>= specialized ) + { + sMessage += " PosixError: "; + sMessage += OString::number(specialized.PosixError); + } + } + { + css::task::ErrorCodeIOException specialized; + if ( caught >>= specialized ) + { + sMessage += " errcode: "; + sMessage += OString::number( specialized.ErrCode ); + } + } + { + css::ucb::CommandFailedException specialized; + if ( caught >>= specialized ) + { + sMessage += "\n Reason: "; + sMessage += exceptionToString( specialized.Reason ); + } + } + { + css::ucb::ContentCreationException specialized; + if ( caught >>= specialized ) + { + sMessage += " eError: "; + sMessage += toOString(comphelper::anyToString( css::uno::Any(specialized.eError) )); + } + } + { + css::ucb::MissingPropertiesException specialized; + if ( caught >>= specialized ) + { + sMessage += " Properties: "; + sMessage += toOString(comphelper::anyToString( css::uno::Any(specialized.Properties) )); + } + } + { + css::ucb::NameClashException specialized; + if ( caught >>= specialized ) + { + sMessage += " Name: "; + sMessage += toOString( specialized.Name ); + } + } + { + css::util::MalformedNumberFormatException specialized; + if ( caught >>= specialized ) + { + sMessage += " CheckPos: "; + sMessage += OString::number( specialized.CheckPos ); + } + } + { + css::xml::dom::DOMException specialized; + if ( caught >>= specialized ) + { + sMessage += " Code: "; + sMessage += toOString(comphelper::anyToString( css::uno::Any(specialized.Code) )); + } + } + { + css::xml::dom::DOMException specialized; + if ( caught >>= specialized ) + { + sMessage += " Code: "; + sMessage += toOString(comphelper::anyToString( css::uno::Any(specialized.Code) )); + } + } + { + css::xml::sax::SAXException specialized; + if ( caught >>= specialized ) + { + sMessage += "\n wrapped: "; + sMessage += exceptionToString( specialized.WrappedException ); + } + } + { + css::xml::sax::SAXParseException specialized; + if ( caught >>= specialized ) + { + sMessage += " PublicId: "; + sMessage += toOString( specialized.PublicId ); + sMessage += " SystemId: "; + sMessage += toOString( specialized.SystemId ); + sMessage += " LineNumber: "; + sMessage += OString::number( specialized.LineNumber ); + sMessage += " ColumnNumber: "; + sMessage += OString::number( specialized.ColumnNumber ); + } + } + return sMessage; +} + +void DbgUnhandledException(const css::uno::Any & caught, const char* currentFunction, const char* fileAndLineNo, + const char* area, const char* explanatory) +{ + OString sMessage( "DBG_UNHANDLED_EXCEPTION in " ); + sMessage += currentFunction; + if (explanatory) + { + sMessage += "\n when: "; + sMessage += explanatory; } - sMessage += "\n"; + sMessage += " exception: "; + sMessage += exceptionToString(caught); if (area == nullptr) area = "legacy.osl"; -- cgit v1.2.3