summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-09-16 18:43:50 +0200
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2021-09-19 18:46:35 +0200
commitadb38e36e3944b47dbf278f882dd07cbabea5ced (patch)
treeaa57c24010a805e9637c6b421b4158d17d677897
parente29689e279442cdcaebea582a008a86861851020 (diff)
tdf#123144 - Always translate an error number to a vba error message
In addition, create a meaningful error message and don't create and artificial error message if there exists a custom one. Change-Id: I682e497ee3fdfe4da80fb17ab41c1b4cf90eb2cb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122206 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
-rw-r--r--basic/inc/strings.hrc1
-rw-r--r--basic/qa/cppunit/test_vba.cxx1
-rw-r--r--basic/qa/vba_tests/error_message.vb34
-rw-r--r--basic/source/classes/sb.cxx14
-rw-r--r--basic/source/runtime/runtime.cxx12
5 files changed, 53 insertions, 9 deletions
diff --git a/basic/inc/strings.hrc b/basic/inc/strings.hrc
index 7aeb2831a64a..64b65db342cc 100644
--- a/basic/inc/strings.hrc
+++ b/basic/inc/strings.hrc
@@ -31,5 +31,6 @@
#define STR_BASICKEY_FORMAT_CURRENCY NC_("STR_BASICKEY_FORMAT_CURRENCY", "@0.00 $;@(0.00 $)")
#define IDS_SBERR_TERMINATED NC_("IDS_SBERR_TERMINATED", "The macro running has been interrupted")
+#define STR_ADDITIONAL_INFO NC_("STR_ADDITIONAL_INFO", "$ERR\nAdditional information: $MSG")
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index 64875b9e1c46..036d3b52cfe4 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -85,6 +85,7 @@ void VBATest::testMiscVBAFunctions()
"day.vb",
"enum.vb",
"error.vb",
+ "error_message.vb",
"Err.Raise.vb",
"exp.vb",
"fix.vb",
diff --git a/basic/qa/vba_tests/error_message.vb b/basic/qa/vba_tests/error_message.vb
new file mode 100644
index 000000000000..7f960573596a
--- /dev/null
+++ b/basic/qa/vba_tests/error_message.vb
@@ -0,0 +1,34 @@
+'
+' This file is part of the LibreOffice project.
+'
+' This Source Code Form is subject to the terms of the Mozilla Public
+' License, v. 2.0. If a copy of the MPL was not distributed with this
+' file, You can obtain one at http://mozilla.org/MPL/2.0/.
+'
+
+Option VBASupport 1
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testErrorMessage
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testErrorMessage()
+
+try: On Error Goto catch
+
+ a = 5
+
+catch:
+
+ ' tdf#123144 - check for a meaningful error message
+ ' Without the fix in place, this test would have failed with
+ ' - Expected: Variable not defined.\n Additional information: a
+ ' - Actual : a
+ TestUtil.AssertEqual(Err.Description, _
+ + "Variable not defined." & Chr$(10) & "Additional information: a", _
+ + "Err.Description failure (Err.Description = " & Err.Description & ")")
+
+End Sub
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 8f2155e6d218..955aabe57c15 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -53,6 +53,8 @@
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/ModuleInfo.hpp>
+#include <strings.hrc>
+
using namespace ::com::sun::star::script;
constexpr OUStringLiteral SB_RTLNAME = u"@SBRTL";
@@ -1570,8 +1572,20 @@ void StarBASIC::MakeErrorText( ErrCode nId, std::u16string_view aMsg )
aMsg1.remove(nResult, aSrgStr.getLength());
aMsg1.insert(nResult, aMsg);
}
+ else if (!aMsg.empty())
+ {
+ // tdf#123144 - create a meaningful error message
+ aMsg1 = BasResId(STR_ADDITIONAL_INFO)
+ .replaceFirst("$ERR", aMsg1)
+ .replaceFirst("$MSG", aMsg);
+ }
GetSbData()->aErrMsg = aMsg1.makeStringAndClear();
}
+ // tdf#123144 - don't use an artifical error message if there is a custom one
+ else if (!aMsg.empty())
+ {
+ GetSbData()->aErrMsg = aMsg;
+ }
else if( nOldID != 0 )
{
OUString aStdMsg = "Error " + OUString::number(nOldID) +
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index cbe62a6a4112..9a2a79e349b5 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -992,15 +992,9 @@ sal_Int32 SbiRuntime::translateErrorToVba( ErrCode nError, OUString& rMsg )
// if there is an error defined it more than likely
// is not the one you want ( some are the same though )
// we really need a new vba compatible error list
- if ( rMsg.isEmpty() )
- {
- StarBASIC::MakeErrorText( nError, rMsg );
- rMsg = StarBASIC::GetErrorText();
- if ( rMsg.isEmpty() ) // no message for err no, need localized resource here
- {
- rMsg = "Internal Object Error:";
- }
- }
+ // tdf#123144 - always translate an error number to a vba error message
+ StarBASIC::MakeErrorText( nError, rMsg );
+ rMsg = StarBASIC::GetErrorText();
// no num? most likely then it *is* really a vba err
sal_uInt16 nVBErrorCode = StarBASIC::GetVBErrorCode( nError );
sal_Int32 nVBAErrorNumber = ( nVBErrorCode == 0 ) ? sal_uInt32(nError) : nVBErrorCode;