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>
This commit is contained in:
Andreas Heinisch
2021-09-16 18:43:50 +02:00
parent e29689e279
commit adb38e36e3
5 changed files with 53 additions and 9 deletions

View File

@@ -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: */

View File

@@ -85,6 +85,7 @@ void VBATest::testMiscVBAFunctions()
"day.vb",
"enum.vb",
"error.vb",
"error_message.vb",
"Err.Raise.vb",
"exp.vb",
"fix.vb",

View File

@@ -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

View File

@@ -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) +

View File

@@ -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;