summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2023-09-30 20:47:46 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-10-03 10:12:41 +0200
commitd9e322d60f65ff20631dab87baa5a2c7c71daaa2 (patch)
treed481e5a4728363b3866b5b5f6dbe64a2780b04a6 /basic
parent64fc701388d1dcf8ae36ba2cc73eb5416a7c3374 (diff)
replace ErrorInfo with simpler mechanism
Instead of returning ErrCode class everywhere, return a new class ErrrCodeMsg, which combines an ErrCode with the other parameters that are used to control the error reporting. I do not change everything that uses ErrCode here, I started from SfxBaseController/SfxMedium and worked outwards. This change serves two purposes (1) Replace the extremely whacky ErrorInfo mechanism we were using to smuggle information into the error handler reporting mechanism with a very straightforward approach of just combining it into the error class. (2) Allow us to capture the source location that produced the error, which makes debugging the source of a problem soooo much easier. Change-Id: I978b8f00c9851b41a216c7ebdef2ef94251d5519 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157440 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic')
-rw-r--r--basic/qa/cppunit/basictest.cxx2
-rw-r--r--basic/qa/cppunit/basictest.hxx4
-rw-r--r--basic/qa/cppunit/test_compiler_checks.cxx4
-rw-r--r--basic/source/basmgr/basmgr.cxx38
-rw-r--r--basic/source/classes/sb.cxx16
-rw-r--r--basic/source/inc/sbintern.hxx2
6 files changed, 34 insertions, 32 deletions
diff --git a/basic/qa/cppunit/basictest.cxx b/basic/qa/cppunit/basictest.cxx
index 8cf9812d5212..13dc8c72e4cb 100644
--- a/basic/qa/cppunit/basictest.cxx
+++ b/basic/qa/cppunit/basictest.cxx
@@ -108,7 +108,7 @@ bool MacroSnippet::Compile()
bool MacroSnippet::HasError() const { return mbError; }
-const ErrCode& MacroSnippet::getError() const { return maErrCode; }
+const ErrCodeMsg& MacroSnippet::getError() const { return maErrCode; }
IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/, bool)
{
diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx
index 1901492bcfab..46af3542b82b 100644
--- a/basic/qa/cppunit/basictest.hxx
+++ b/basic/qa/cppunit/basictest.hxx
@@ -23,7 +23,7 @@ class MacroSnippet
{
private:
bool mbError;
- ErrCode maErrCode;
+ ErrCodeMsg maErrCode;
BasicDLL maDll; // we need a dll instance for resource manager etc.
SbModuleRef mpMod;
StarBASICRef mpBasic;
@@ -46,7 +46,7 @@ public:
DECL_LINK(BasicErrorHdl, StarBASIC*, bool);
bool HasError() const;
- const ErrCode& getError() const;
+ const ErrCodeMsg& getError() const;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/qa/cppunit/test_compiler_checks.cxx b/basic/qa/cppunit/test_compiler_checks.cxx
index 044977670e62..773719e9fd45 100644
--- a/basic/qa/cppunit/test_compiler_checks.cxx
+++ b/basic/qa/cppunit/test_compiler_checks.cxx
@@ -21,7 +21,7 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument)
"End Sub\n");
aMacro.Compile();
CPPUNIT_ASSERT(aMacro.HasError());
- CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().GetCode());
}
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument)
@@ -30,7 +30,7 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument)
"End Sub\n");
aMacro.Compile();
CPPUNIT_ASSERT(aMacro.HasError());
- CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().GetCode());
}
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157)
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index f7a4fb2ae192..6e2ce76d37ae 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -300,7 +300,7 @@ void SAL_CALL BasMgrContainerListenerImpl::elementRemoved( const container::Cont
}
}
-BasicError::BasicError( ErrCode nId, BasicErrorReason nR )
+BasicError::BasicError( ErrCodeMsg nId, BasicErrorReason nR )
{
nErrorId = nId;
nReason = nR;
@@ -609,8 +609,8 @@ void BasicManager::ImpMgrNotLoaded( const OUString& rStorageName )
{
// pErrInf is only destroyed if the error os processed by an
// ErrorHandler
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, rStorageName, DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENMGRSTREAM);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_MGROPEN, rStorageName, DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::OPENMGRSTREAM);
// Create a stdlib otherwise we crash!
BasicLibInfo* pStdLibInfo = CreateLibInfo();
@@ -749,8 +749,8 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
xManagerStream->Seek( nBasicStartOff );
if (!ImplLoadBasic( *xManagerStream, maLibs.front()->GetLibRef() ))
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, aStorName, DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENMGRSTREAM);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_MGROPEN, aStorName, DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::OPENMGRSTREAM);
// and it proceeds ...
}
xManagerStream->Seek( nBasicEndOff+1 ); // +1: 0x00 as separator
@@ -799,8 +799,8 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
}
else
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::STORAGENOTFOUND);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD, aStorName, DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::STORAGENOTFOUND);
}
} while (nLibPos>=0);
}
@@ -868,8 +868,8 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStora
if ( !xBasicStorage.is() || xBasicStorage->GetError() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, xStorage->GetName(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENLIBSTORAGE);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_MGROPEN, xStorage->GetName(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::OPENLIBSTORAGE);
}
else
{
@@ -877,8 +877,8 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStora
tools::SvRef<SotStorageStream> xBasicStream = xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
if ( !xBasicStream.is() || xBasicStream->GetError() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENLIBSTREAM);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::OPENLIBSTREAM);
}
else
{
@@ -900,8 +900,8 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStora
}
if ( !bLoaded )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, pLibInfo->GetLibName(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::BASICLOADERROR);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD, pLibInfo->GetLibName(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::BASICLOADERROR);
}
else
{
@@ -1084,8 +1084,8 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
if( !nLib || nLib < maLibs.size() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::STDLIB);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::STDLIB);
return false;
}
@@ -1120,8 +1120,8 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
if ( !xBasicStorage.is() || xBasicStorage->GetError() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENLIBSTORAGE);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::OPENLIBSTORAGE);
}
else if (xBasicStorage->IsStream((*itLibInfo)->GetLibName()))
{
@@ -1255,8 +1255,8 @@ bool BasicManager::LoadLib( sal_uInt16 nLib )
}
else
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, OUString(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::LIBNOTFOUND);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD, OUString(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf, BasicErrorReason::LIBNOTFOUND);
}
return bDone;
}
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 1070f1986e38..9d3a7706189c 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -1429,7 +1429,7 @@ sal_uInt16 StarBASIC::GetCol1() { return GetSbData()->nCol1; }
sal_uInt16 StarBASIC::GetCol2() { return GetSbData()->nCol2; }
// Specific to error handler
-ErrCode const & StarBASIC::GetErrorCode() { return GetSbData()->nCode; }
+ErrCodeMsg const & StarBASIC::GetErrorCode() { return GetSbData()->nCode; }
const OUString& StarBASIC::GetErrorText() { return GetSbData()->aErrMsg; }
// From 1996-03-29:
@@ -1531,7 +1531,7 @@ ErrCode StarBASIC::GetSfxFromVBError( sal_uInt16 nError )
}
// set Error- / Break-data
-void StarBASIC::SetErrorData( ErrCode nCode, sal_uInt16 nLine,
+void StarBASIC::SetErrorData( const ErrCodeMsg& nCode, sal_uInt16 nLine,
sal_uInt16 nCol1, sal_uInt16 nCol2 )
{
SbiGlobals& aGlobals = *GetSbData();
@@ -1620,11 +1620,12 @@ bool StarBASIC::CError( ErrCode code, const OUString& rMsg,
MakeErrorText( code, rMsg );
// Implementation of the code for the string transport to SFX-Error
+ ErrCodeMsg nErr = code;
if( !rMsg.isEmpty() )
{
- code = *new StringErrorInfo( code, rMsg );
+ nErr = ErrCodeMsg( code, rMsg );
}
- SetErrorData( code, l, c1, c2 );
+ SetErrorData( nErr, l, c1, c2 );
GetSbData()->bCompilerError = true;
bool bRet;
if( GetSbData()->aErrHdl.IsSet() )
@@ -1651,6 +1652,7 @@ bool StarBASIC::RTError( ErrCode code, const OUString& rMsg, sal_Int32 l, sal_In
MakeErrorText( c, rMsg );
// Implementation of the code for the string transport to SFX-Error
+ ErrCodeMsg nErr = code;
if( !rMsg.isEmpty() )
{
// very confusing, even though MakeErrorText sets up the error text
@@ -1661,15 +1663,15 @@ bool StarBASIC::RTError( ErrCode code, const OUString& rMsg, sal_Int32 l, sal_In
{
OUString aTmp = "\'" + OUString::number(SbxErrObject::getUnoErrObject()->getNumber()) +
"\'\n" + (!GetSbData()->aErrMsg.isEmpty() ? GetSbData()->aErrMsg : rMsg);
- code = *new StringErrorInfo( code, aTmp );
+ nErr = ErrCodeMsg( code, aTmp );
}
else
{
- code = *new StringErrorInfo( code, rMsg );
+ nErr = ErrCodeMsg( code, rMsg );
}
}
- SetErrorData( code, l, c1, c2 );
+ SetErrorData( nErr, l, c1, c2 );
if( GetSbData()->aErrHdl.IsSet() )
{
return GetSbData()->aErrHdl.Call( this );
diff --git a/basic/source/inc/sbintern.hxx b/basic/source/inc/sbintern.hxx
index 5ed41d5fb138..ae18e0f9e30b 100644
--- a/basic/source/inc/sbintern.hxx
+++ b/basic/source/inc/sbintern.hxx
@@ -124,7 +124,7 @@ struct SbiGlobals
short nInst; // number of BASICs
Link<StarBASIC*,bool> aErrHdl; // global error handler
Link<StarBASIC*,BasicDebugFlags> aBreakHdl; // global break handler
- ErrCode nCode;
+ ErrCodeMsg nCode;
sal_Int32 nLine;
sal_Int32 nCol1,nCol2; // from... to...
bool bCompilerError; // flag for compiler error