ScriptForge (SF_Exception) Return codes

So far, an exception raised in a user script
and detected by ScriptForge gave next behaviour:
- an error message was displayed to the user (1)
- the same error message was recorded in the
  console (2)
- the execution of the script was stopped (3)

The actual commit introduces 4 new properties
in the SF_Exception service.
Next two boolean properties may optionally
change above behaviour:
  exception.ReportScriptErrors (default = True)
  exception.StopWhenError (default = True)
They may change resp. behaviours (1) and (3).
Note that behaviour (2) is preserved anyway.
Their values are set until they are set
again or until the LO session expires.

When StopWhenError is set to False, next two
properties allow to test the success of the
last call to the ScriptForge API and to
define an appropriate action, including the
continuation of the process:
  exception.ReturnCode
  exception.ReturnCodeDescription

Example:
    exc = CreateScriptService("Exception")
    fs = CreateScriptService("FileSystem")
    exc.ReportScriptErrors = False
    exc.StopWhenError = False
    fs.OpenTextFile("/aaa/bbb")
    if exc.ReturnCode = "UNKNOWNFILEERROR":
        ...

The test on the return code must precede any
next call to any ScriptForge API entry.

The list of the available return codes is
listed in the SF_Exception.xba source code.

These changes are applicable both for Basic
and Python user scripts.
The user documentation should be reviewed.

Change-Id: I6d274e54ee37702f244e729ea5c9d1751b69abec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183486
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
This commit is contained in:
Jean-Pierre Ledure 2025-03-29 16:09:57 +01:00
parent 11f10c4868
commit c8d2751a90
7 changed files with 154 additions and 36 deletions

View File

@ -33,10 +33,17 @@ Option Explicit
&apos;&apos;&apos; or during control events processing &apos;&apos;&apos; or during control events processing
&apos;&apos;&apos; =&gt; DebugPrint() &apos;&apos;&apos; =&gt; DebugPrint()
&apos;&apos;&apos; &apos;&apos;&apos;
&apos;&apos;&apos; The usual behaviour of the application when an error occurs is: &apos;&apos;&apos; The behaviour of the application when an error occurs is:
&apos;&apos;&apos; 1. Log the error in the console &apos;&apos;&apos; 1. Log the error in the console. This is always done
&apos;&apos;&apos; 2, Inform the user about the error with either a standard or a customized message &apos;&apos;&apos; 2. Inform the user about the error with either a standard or a localized message
&apos;&apos;&apos; 3. Optionally, stop the execution of the current macro &apos;&apos;&apos; To force a silent mode, set :
&apos;&apos;&apos; exception.ReportScriptErrors = False &apos; Default = True
&apos;&apos;&apos; 3. To not stop the execution of the current macro when ScriptForge detects
&apos;&apos;&apos; a user script error, set :
&apos;&apos;&apos; exception.StopWhenError = False &apos; Default = True
&apos;&apos;&apos; It then makes sense before further processing to explore the values of
&apos;&apos;&apos; exception.ReturnCode &apos; Short error description
&apos;&apos;&apos; exception.ReturnCodeDescription &apos; Long error description
&apos;&apos;&apos; &apos;&apos;&apos;
&apos;&apos;&apos; Detailed user documentation: &apos;&apos;&apos; Detailed user documentation:
&apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_exception.html?DbPAR=BASIC &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_exception.html?DbPAR=BASIC
@ -205,6 +212,41 @@ Property Let Number(ByVal pvNumber As Variant)
_PropertySet &quot;Number&quot;, pvNumber _PropertySet &quot;Number&quot;, pvNumber
End Property &apos; ScriptForge.SF_Exception.Number (let) End Property &apos; ScriptForge.SF_Exception.Number (let)
REM -----------------------------------------------------------------------------
Property Get ReportScriptErrors() As Variant
&apos;&apos;&apos; Indicates whether script errors are displayed in a message box when they occur
&apos;&apos;&apos; Example:
&apos;&apos;&apos; myException.ReportScriptErrors
ReportScriptErrors = _PropertyGet(&quot;ReportScriptErrors&quot;)
End Property &apos; ScriptForge.SF_Exception.ReportScriptErrors (get)
REM -----------------------------------------------------------------------------
Property Let ReportScriptErrors(ByVal pvReportScriptErrors As Variant)
&apos;&apos;&apos; When set to False, an error occur silently. Useful f.i. in Calc user-defined functions.
&apos;&apos;&apos; The set value is preserved until it is explicitly set again.
&apos;&apos;&apos; Example:
&apos;&apos;&apos; myException.ReportScriptErrors = False
_PropertySet &quot;ReportScriptErrors&quot;, pvReportScriptErrors
End Property &apos; ScriptForge.SF_Exception.ReportScriptErrors (let)
REM -----------------------------------------------------------------------------
Property Get ReturnCode() As String
&apos;&apos;&apos; Returns the code returned by the last call to the ScriptForge API from a user script.
&apos;&apos;&apos; It is the zero-length string if everything ran without error
&apos;&apos;&apos; Example:
&apos;&apos;&apos; myException.ReturnCode
ReturnCode = _PropertyGet(&quot;ReturnCode&quot;)
End Property &apos; ScriptForge.SF_Exception.ReturnCode (get)
REM -----------------------------------------------------------------------------
Property Get ReturnCodeDescription() As String
&apos;&apos;&apos; Returns the localized description of the code returned by the last call to the ScriptForge API from a user script.
&apos;&apos;&apos; It is the zero-length string if everything ran without error
&apos;&apos;&apos; Example:
&apos;&apos;&apos; myException.ReturnCodeDescription
ReturnCodeDescription = _PropertyGet(&quot;ReturnCodeDescription&quot;)
End Property &apos; ScriptForge.SF_Exception.ReturnCodeDescription (get)
REM ----------------------------------------------------------------------------- REM -----------------------------------------------------------------------------
Property Get Source() As Variant Property Get Source() As Variant
&apos;&apos;&apos; Returns the location of the last error that has occurred &apos;&apos;&apos; Returns the location of the last error that has occurred
@ -221,6 +263,23 @@ Property Let Source(ByVal pvSource As Variant)
_PropertySet &quot;Source&quot;, pvSource _PropertySet &quot;Source&quot;, pvSource
End Property &apos; ScriptForge.SF_Exception.Source (let) End Property &apos; ScriptForge.SF_Exception.Source (let)
REM -----------------------------------------------------------------------------
Property Get StopWhenError() As Variant
&apos;&apos;&apos; Indicates whether the Basic process is stopped when ScriptForge detects a user script error
&apos;&apos;&apos; Example:
&apos;&apos;&apos; myException.StopWhenError
StopWhenError = _PropertyGet(&quot;StopWhenError&quot;)
End Property &apos; ScriptForge.SF_Exception.StopWhenError (get)
REM -----------------------------------------------------------------------------
Property Let StopWhenError(ByVal pvStopWhenError As Variant)
&apos;&apos;&apos; When set to False, the Basic process continues when ScriptForge detects a user script error. Default = True.
&apos;&apos;&apos; The set value is preserved until it is explicitly set again.
&apos;&apos;&apos; Example:
&apos;&apos;&apos; myException.StopWhenError = False
_PropertySet &quot;StopWhenError&quot;, pvStopWhenError
End Property &apos; ScriptForge.SF_Exception.StopWhenError (let)
REM ----------------------------------------------------------------------------- REM -----------------------------------------------------------------------------
Property Get ObjectType As String Property Get ObjectType As String
&apos;&apos;&apos; Only to enable object representation &apos;&apos;&apos; Only to enable object representation
@ -237,7 +296,7 @@ REM ===================================================================== METHOD
REM ----------------------------------------------------------------------------- REM -----------------------------------------------------------------------------
Public Sub Clear() Public Sub Clear()
&apos;&apos;&apos; Reset the current error status and clear the SF_Exception object &apos;&apos;&apos; Reset the current error status, clear the SF_Exception object and reinitialize the return code.
&apos;&apos;&apos; Args: &apos;&apos;&apos; Args:
&apos;&apos;&apos; Examples: &apos;&apos;&apos; Examples:
&apos;&apos;&apos; On Local Error GoTo Catch &apos;&apos;&apos; On Local Error GoTo Catch
@ -260,6 +319,11 @@ Try:
._SysDescription = &quot;&quot; ._SysDescription = &quot;&quot;
End With End With
With _SF_
.ReturnCode = &quot;&quot;
.ReturnCodeDescription = &quot;&quot;
End With
Finally: Finally:
On Error GoTo 0 On Error GoTo 0
Exit Sub Exit Sub
@ -320,7 +384,7 @@ Try:
&apos; Terminate the modal dialog &apos; Terminate the modal dialog
If Modal Then If Modal Then
Set .ConsoleControl = .ConsoleControl.Dispose() Set .ConsoleControl = .ConsoleControl.Dispose()
Set .ConsoleDialog = .ConsoleDialog.Dispose() .ConsoleDialog.Terminate()
End If End If
End If End If
End With End With
@ -527,7 +591,7 @@ Const cstSubArgs = &quot;&quot;
GetProperty = Null GetProperty = Null
Check: Check:
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then If SF_Utils._EnterFunction(cstThisSub, cstSubArgs, pbReinitRC := False) Then &apos; Keep return codes untouched
If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
End If End If
@ -566,7 +630,11 @@ Public Function Properties() As Variant
Properties = Array( _ Properties = Array( _
&quot;Description&quot; _ &quot;Description&quot; _
, &quot;Number&quot; _ , &quot;Number&quot; _
, &quot;ReportScriptErrors&quot; _
, &quot;ReturnCode&quot; _
, &quot;ReturnCodeDescription&quot; _
, &quot;Source&quot; _ , &quot;Source&quot; _
, &quot;StopWhenError&quot; _
) )
End Function &apos; ScriptForge.SF_Exception.Properties End Function &apos; ScriptForge.SF_Exception.Properties
@ -620,6 +688,7 @@ REM ----------------------------------------------------------------------------
Public Sub Raise(Optional ByVal Number As Variant _ Public Sub Raise(Optional ByVal Number As Variant _
, Optional ByVal Source As Variant _ , Optional ByVal Source As Variant _
, Optional ByVal Description As Variant _ , Optional ByVal Description As Variant _
, Optional ByVal _Warning As Variant _
) )
&apos;&apos;&apos; Generate a run-time error. An error message is displayed to the user and logged &apos;&apos;&apos; Generate a run-time error. An error message is displayed to the user and logged
&apos;&apos;&apos; in the console. The execution is STOPPED &apos;&apos;&apos; in the console. The execution is STOPPED
@ -628,6 +697,7 @@ Public Sub Raise(Optional ByVal Number As Variant _
&apos;&apos;&apos; If numeric and &lt;= 2000, it is considered a LibreOffice Basic run-time error (default = Err) &apos;&apos;&apos; If numeric and &lt;= 2000, it is considered a LibreOffice Basic run-time error (default = Err)
&apos;&apos;&apos; Source: the line where the error occurred (default = Erl) or any string describing the location of the error &apos;&apos;&apos; Source: the line where the error occurred (default = Erl) or any string describing the location of the error
&apos;&apos;&apos; Description: the error message to log in the console and to display to the user &apos;&apos;&apos; Description: the error message to log in the console and to display to the user
&apos;&apos;&apos; _Warning: When True, do not stop the process. FOR INTERNAL USE ONLY
&apos;&apos;&apos; Examples: &apos;&apos;&apos; Examples:
&apos;&apos;&apos; On Local Error GoTo Catch &apos;&apos;&apos; On Local Error GoTo Catch
&apos;&apos;&apos; &apos; ... &apos;&apos;&apos; &apos; ...
@ -650,6 +720,7 @@ Check:
If IsMissing(Number) Or IsEmpty(Number) Then Number = -1 If IsMissing(Number) Or IsEmpty(Number) Then Number = -1
If IsMissing(Source) Or IsEmpty(Source) Then Source = -1 If IsMissing(Source) Or IsEmpty(Source) Then Source = -1
If IsMissing(Description) Or IsEmpty(Description) Then Description = &quot;&quot; If IsMissing(Description) Or IsEmpty(Description) Then Description = &quot;&quot;
If IsMissing(_Warning) Or IsEmpty(_Warning) Then _Warning = False
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
If Not SF_Utils._Validate(Number, &quot;Number&quot;, Array(V_STRING, V_NUMERIC)) Then GoTo Finally If Not SF_Utils._Validate(Number, &quot;Number&quot;, Array(V_STRING, V_NUMERIC)) Then GoTo Finally
If Not SF_Utils._Validate(Source, &quot;Source&quot;, Array(V_STRING, V_NUMERIC)) Then GoTo Finally If Not SF_Utils._Validate(Source, &quot;Source&quot;, Array(V_STRING, V_NUMERIC)) Then GoTo Finally
@ -670,7 +741,7 @@ Try:
Set L10N = _SF_._GetLocalizedInterface() Set L10N = _SF_._GetLocalizedInterface()
sMessage = L10N.GetText(&quot;LONGERRORDESC&quot;, .Number, .Source, .Description) sMessage = L10N.GetText(&quot;LONGERRORDESC&quot;, .Number, .Source, .Description)
.DebugPrint(sMessage) .DebugPrint(sMessage)
If _SF_.DisplayEnabled Then MsgBox L10N.GetText(&quot;ERRORNUMBER&quot;, .Number) _ If _SF_.ReportScriptErrors Then MsgBox L10N.GetText(&quot;ERRORNUMBER&quot;, .Number) _
&amp; SF_String.sfNewLine &amp; L10N.GetText(&quot;ERRORLOCATION&quot;, .Source) _ &amp; SF_String.sfNewLine &amp; L10N.GetText(&quot;ERRORLOCATION&quot;, .Source) _
&amp; SF_String.sfNewLine &amp; .Description _ &amp; SF_String.sfNewLine &amp; .Description _
, MB_OK + MB_ICONSTOP _ , MB_OK + MB_ICONSTOP _
@ -679,7 +750,7 @@ Try:
Finally: Finally:
SF_Utils._ExitFunction(cstThisSub) SF_Utils._ExitFunction(cstThisSub)
If _SF_.StopWhenError Then If Not _Warning Then
SF_Exception.Clear() SF_Exception.Clear()
_SF_._StackReset() _SF_._StackReset()
Stop Stop
@ -729,7 +800,7 @@ Try:
&apos; Log and display &apos; Log and display
sMessage = L10N.GetText(&quot;LONGERRORDESC&quot;, .Number, .Source, .Description) sMessage = L10N.GetText(&quot;LONGERRORDESC&quot;, .Number, .Source, .Description)
.DebugPrint(sMessage) .DebugPrint(sMessage)
If _SF_.DisplayEnabled Then If _SF_.ReportScriptErrors Then
sMessage = sLocation _ sMessage = sLocation _
&amp; L10N.GetText(&quot;INTERNALERROR&quot;) _ &amp; L10N.GetText(&quot;INTERNALERROR&quot;) _
&amp; L10N.GetText(&quot;ERRORLOCATION&quot;, Source &amp; &quot;/&quot; &amp; .Source) &amp; SF_String.sfNewLine &amp; .Description _ &amp; L10N.GetText(&quot;ERRORLOCATION&quot;, Source &amp; &quot;/&quot; &amp; .Source) &amp; SF_String.sfNewLine &amp; .Description _
@ -744,7 +815,7 @@ Try:
Finally: Finally:
_SF_._StackReset() _SF_._StackReset()
If _SF_.StopWhenError Then Stop Stop &apos; Unconditional stop whatever the value of the StopWhenError flag
Exit Sub Exit Sub
Catch: Catch:
GoTo Finally GoTo Finally
@ -1096,7 +1167,7 @@ Try:
_SF_._AddToConsole(sMessage) _SF_._AddToConsole(sMessage)
&apos; Display fatal event, if relevant (default) &apos; Display fatal event, if relevant (default)
If _SF_.DisplayEnabled Then If _SF_.ReportScriptErrors Then
If _SF_.StopWhenError Then sMessage = sMessage &amp; &quot;\n&quot; &amp; &quot;\n&quot; &amp; &quot;\n&quot; &amp; L10N.GetText(&quot;STOPEXECUTION&quot;) If _SF_.StopWhenError Then sMessage = sMessage &amp; &quot;\n&quot; &amp; &quot;\n&quot; &amp; &quot;\n&quot; &amp; L10N.GetText(&quot;STOPEXECUTION&quot;)
&apos; Do you need more help ? &apos; Do you need more help ?
If Len(sMethod) &gt; 0 Then If Len(sMethod) &gt; 0 Then
@ -1115,8 +1186,12 @@ Try:
Finally: Finally:
SF_Utils._ExitFunction(cstThisSub) SF_Utils._ExitFunction(cstThisSub)
_SF_._StackReset() With _SF_
If _SF_.StopWhenError Then Stop ._StackReset()
If .StopWhenError Then Stop
.ReturnCode = ErrorCode
.ReturnCodeDescription = sMessage
End With
Exit Sub Exit Sub
Catch: Catch:
GoTo Finally GoTo Finally
@ -1145,7 +1220,6 @@ Public Sub RaiseWarning(Optional ByVal Number As Variant _
&apos;&apos;&apos; SF_Exception.RaiseWarning(&quot;MYAPPERROR&quot;, &quot;myFunction&quot;, &quot;Application error&quot;) &apos;&apos;&apos; SF_Exception.RaiseWarning(&quot;MYAPPERROR&quot;, &quot;myFunction&quot;, &quot;Application error&quot;)
&apos;&apos;&apos; SF_Exception.RaiseWarning(,, &quot;To divide by zero is not a good idea !&quot;) &apos;&apos;&apos; SF_Exception.RaiseWarning(,, &quot;To divide by zero is not a good idea !&quot;)
Dim bStop As Boolean &apos; Alias for stop switch
Const cstThisSub = &quot;Exception.RaiseWarning&quot; Const cstThisSub = &quot;Exception.RaiseWarning&quot;
Const cstSubArgs = &quot;[Number=Err], [Source=Erl], [Description]&quot; Const cstSubArgs = &quot;[Number=Err], [Source=Erl], [Description]&quot;
@ -1164,13 +1238,10 @@ Check:
End If End If
Try: Try:
bStop = _SF_.StopWhenError &apos; Store current value to reset it before leaving the Sub SF_Exception.Raise(Number, Source, Description, _Warning := True)
_SF_.StopWhenError = False
SF_Exception.Raise(Number, Source, Description)
Finally: Finally:
SF_Utils._ExitFunction(cstThisSub) SF_Utils._ExitFunction(cstThisSub)
_SF_.StopWhenError = bStop
Exit Sub Exit Sub
Catch: Catch:
GoTo Finally GoTo Finally
@ -1248,7 +1319,7 @@ End Sub &apos; ScriptForge.SF_Exception._CloseConsole
REM ----------------------------------------------------------------------------- REM -----------------------------------------------------------------------------
Private Sub _ConsoleRefresh() Private Sub _ConsoleRefresh()
&apos;&apos;&apos; Reload the content of the console in the dialog &apos;&apos;&apos; Reload the content of the console in the dialog
&apos;&apos;&apos; Needed when console first loaded or when totally or partially cleared &apos;&apos;&apos; Needed when console loaded for the first time or when totally or partially cleared
With _SF_ With _SF_
&apos; Do nothing if console inactive &apos; Do nothing if console inactive
@ -1302,8 +1373,16 @@ Const cstSubArgs = &quot;&quot;
If _Description = &quot;&quot; Then _PropertyGet = _SysDescription Else _PropertyGet = _Description If _Description = &quot;&quot; Then _PropertyGet = _SysDescription Else _PropertyGet = _Description
Case &quot;Number&quot; Case &quot;Number&quot;
If IsEmpty(_Number) Then _PropertyGet = _SysNumber Else _PropertyGet = _Number If IsEmpty(_Number) Then _PropertyGet = _SysNumber Else _PropertyGet = _Number
Case &quot;ReportScriptErrors&quot;
_PropertyGet = _SF_.ReportScriptErrors
Case &quot;ReturnCode&quot;
_PropertyGet = _SF_.ReturnCode
Case &quot;ReturnCodeDescription&quot;
_PropertyGet = _SF_.ReturnCodeDescription
Case &quot;Source&quot; Case &quot;Source&quot;
If IsEmpty(_Source) Then _PropertyGet = _SysSource Else _PropertyGet = _Source If IsEmpty(_Source) Then _PropertyGet = _SysSource Else _PropertyGet = _Source
Case &quot;StopWhenError&quot;
_PropertyGet = _SF_.StopWhenError
Case Else Case Else
_PropertyGet = Null _PropertyGet = Null
End Select End Select
@ -1346,6 +1425,8 @@ Const cstSubArgs = &quot;&quot;
_Number = Empty _Number = Empty
Case Else Case Else
End Select End Select
Case &quot;ReportScriptErrors&quot;
If VarType(pvValue) = V_BOOLEAN Then _SF_.ReportScriptErrors = pvValue
Case &quot;Source&quot; Case &quot;Source&quot;
Select Case SF_Utils._VarTypeExt(pvValue) Select Case SF_Utils._VarTypeExt(pvValue)
Case V_STRING Case V_STRING
@ -1354,6 +1435,8 @@ Const cstSubArgs = &quot;&quot;
_Source = CLng(pvValue) _Source = CLng(pvValue)
Case Else Case Else
End Select End Select
Case &quot;StopWhenError&quot;
If VarType(pvValue) = V_BOOLEAN Then _SF_.StopWhenError = pvValue
Case Else Case Else
End Select End Select

View File

@ -34,8 +34,10 @@ Private ErrorHandler As Boolean &apos; True = error handling active, False = in
Private ConsoleLines() As Variant &apos; Array of messages displayable in console Private ConsoleLines() As Variant &apos; Array of messages displayable in console
Private ConsoleDialog As Object &apos; SFDialogs.Dialog object Private ConsoleDialog As Object &apos; SFDialogs.Dialog object
Private ConsoleControl As Object &apos; SFDialogs.DialogControl object Private ConsoleControl As Object &apos; SFDialogs.DialogControl object
Private DisplayEnabled As Boolean &apos; When True, display of console or error messages is allowed Private ReportScriptErrors As Boolean &apos; When True, error messages are displayed to the user
Private StopWhenError As Boolean &apos; When True, process stops after error &gt; &quot;WARNING&quot; Private StopWhenError As Boolean &apos; When True, process stops after error &gt; &quot;WARNING&quot;
Private ReturnCode As String &apos; The short error code
Private ReturnCodeDescription As String &apos; The long and localized error message
Private TriggeredByPython As Boolean &apos; When True, the actual user script is a Python script Private TriggeredByPython As Boolean &apos; When True, the actual user script is a Python script
Private DebugMode As Boolean &apos; When True, log enter/exit each official Sub Private DebugMode As Boolean &apos; When True, log enter/exit each official Sub
@ -109,8 +111,10 @@ Private Sub Class_Initialize()
ConsoleLines = Array() ConsoleLines = Array()
Set ConsoleDialog = Nothing Set ConsoleDialog = Nothing
Set ConsoleControl = Nothing Set ConsoleControl = Nothing
DisplayEnabled = True ReportScriptErrors = True
StopWhenError = True StopWhenError = True
ReturnCode = &quot;&quot;
ReturnCodeDescription = &quot;&quot;
TriggeredByPython = False TriggeredByPython = False
DebugMode = False DebugMode = False
Set ProgressBarDialog = Nothing Set ProgressBarDialog = Nothing

View File

@ -153,7 +153,10 @@ Finally:
End Function &apos; ScriptForge.SF_Utils._CStrToDate End Function &apos; ScriptForge.SF_Utils._CStrToDate
REM ----------------------------------------------------------------------------- REM -----------------------------------------------------------------------------
Public Function _EnterFunction(ByVal psSub As String, Optional ByVal psArgs As String) As Boolean Public Function _EnterFunction(ByVal psSub As String _
, Optional ByVal psArgs As String _
, Optional ByVal pbReinitRC As Variant _
) As Boolean
&apos;&apos;&apos; Called on top of each public function &apos;&apos;&apos; Called on top of each public function
&apos;&apos;&apos; Used to trace routine in/outs (debug mode) &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
&apos;&apos;&apos; and to allow the explicit mention of the user call which caused an error &apos;&apos;&apos; and to allow the explicit mention of the user call which caused an error
@ -164,11 +167,17 @@ Public Function _EnterFunction(ByVal psSub As String, Optional ByVal psArgs As S
If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
If IsMissing(psArgs) Then psArgs = &quot;&quot; If IsMissing(psArgs) Then psArgs = &quot;&quot;
If IsMissing(pbReinitRC) Then pbReinitRC = True
With _SF_ With _SF_
If .StackLevel = 0 Then If .StackLevel = 0 Then
.MainFunction = psSub .MainFunction = psSub
.MainFunctionArgs = psArgs .MainFunctionArgs = psArgs
_EnterFunction = True _EnterFunction = True
If pbReinitRC Then
&apos; Reinitialize return code status
.ReturnCode = &quot;&quot;
.ReturnCodeDescription = &quot;&quot;
End If
Else Else
_EnterFunction = False _EnterFunction = False
End If End If

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false">
<library:element library:name="dlgProgress"/>
<library:element library:name="dlgConsole"/> <library:element library:name="dlgConsole"/>
<library:element library:name="dlgProgress"/>
</library:library> </library:library>

View File

@ -1074,7 +1074,10 @@ class SFScriptForge:
serviceimplementation = 'basic' serviceimplementation = 'basic'
servicename = 'ScriptForge.Exception' servicename = 'ScriptForge.Exception'
servicesynonyms = ('exception', 'scriptforge.exception') servicesynonyms = ('exception', 'scriptforge.exception')
serviceproperties = dict() serviceproperties = dict(ReportScriptErrors = 3, ReturnCode = 1, ReturnCodeDescription = 1, StopWhenError = 3)
def Clear(self):
return self.ExecMethod(self.vbMethod, 'Clear')
def Console(self, modal = True): def Console(self, modal = True):
# From Python, the current XComponentContext must be added as last argument # From Python, the current XComponentContext must be added as last argument
@ -1170,7 +1173,7 @@ class SFScriptForge:
serviceimplementation = 'basic' serviceimplementation = 'basic'
servicename = 'ScriptForge.FileSystem' servicename = 'ScriptForge.FileSystem'
servicesynonyms = ('filesystem', 'scriptforge.filesystem') servicesynonyms = ('filesystem', 'scriptforge.filesystem')
serviceproperties = dict(FileNaming = 3, ConfigFolder = 1, ExtensionsFolder = 1, HomeFolder = 1, serviceproperties = dict(ConfigFolder = 1, ExtensionsFolder = 1, FileNaming = 3, HomeFolder = 1,
InstallFolder = 1, TemplatesFolder = 1, TemporaryFolder = 1, InstallFolder = 1, TemplatesFolder = 1, TemporaryFolder = 1,
UserTemplatesFolder = 1) # 1 because FileNaming determines every time the folder format UserTemplatesFolder = 1) # 1 because FileNaming determines every time the folder format
# Open TextStream constants # Open TextStream constants

View File

@ -780,7 +780,26 @@ class SFScriptForge:
Console entries can be dumped to a text file or visualized in a dialogue. Console entries can be dumped to a text file or visualized in a dialogue.
""" """
def Console(self, modal: bool = ...): ReportScriptErrors: bool
""" When set to ``False``, an error occur silently. Useful f.i. in Calc user-defined functions.
The set value is preserved until it is explicitly set again. """
ReturnCode: str
""" Returns the code returned by the last call to the ScriptForge API from a user script.
It is the zero-length string if everything ran without error. """
ReturnCodeDescription: str
""" Returns the localized description of the code returned by the last call to the ScriptForge API
from a user script. It is the zero-length string if everything ran without error. """
StopWhenError: bool
""" When set to ``False``, the process continues when ScriptForge detects a user script error.
Default = ``True``. The set value is preserved until it is explicitly set again. """
def Clear(self):
"""
Reset the current error status and return code.
"""
...
def Console(self, modal: bool = ...) -> None:
""" """
Displays the console messages in a modal or non-modal dialog. In both modes, all the past messages Displays the console messages in a modal or non-modal dialog. In both modes, all the past messages
issued by a ``DebugPrint()`` method or resulting from an exception are displayed. In non-modal mode, issued by a ``DebugPrint()`` method or resulting from an exception are displayed. In non-modal mode,
@ -796,7 +815,7 @@ class SFScriptForge:
""" """
... ...
def ConsoleClear(self, keep: int = ...): def ConsoleClear(self, keep: int = ...) -> None:
""" """
Clears the console keeping an optional number of recent messages. If the console is activated in non-modal mode, Clears the console keeping an optional number of recent messages. If the console is activated in non-modal mode,
it is refreshed. it is refreshed.

View File

@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false">
<library:element library:name="_ModuleModel"/>
<library:element library:name="SF_Session"/>
<library:element library:name="SF_Dictionary"/>
<library:element library:name="SF_Exception"/> <library:element library:name="SF_Exception"/>
<library:element library:name="SF_Dictionary"/>
<library:element library:name="SF_Services"/> <library:element library:name="SF_Services"/>
<library:element library:name="SF_UI"/> <library:element library:name="SF_UI"/>
<library:element library:name="SF_Timer"/>
<library:element library:name="SF_FileSystem"/>
<library:element library:name="SF_TextStream"/> <library:element library:name="SF_TextStream"/>
<library:element library:name="SF_Array"/> <library:element library:name="SF_Array"/>
<library:element library:name="SF_Region"/>
<library:element library:name="SF_L10N"/>
<library:element library:name="SF_PythonHelper"/> <library:element library:name="SF_PythonHelper"/>
<library:element library:name="SF_Platform"/> <library:element library:name="SF_Platform"/>
<library:element library:name="SF_String"/> <library:element library:name="SF_String"/>
<library:element library:name="SF_Session"/>
<library:element library:name="_ModuleModel"/>
<library:element library:name="_CodingConventions"/> <library:element library:name="_CodingConventions"/>
<library:element library:name="SF_Utils"/> <library:element library:name="SF_Utils"/>
<library:element library:name="SF_Root"/>
<library:element library:name="__License"/> <library:element library:name="__License"/>
<library:element library:name="SF_Region"/> <library:element library:name="SF_Root"/>
<library:element library:name="SF_L10N"/> <library:element library:name="SF_Timer"/>
<library:element library:name="SF_FileSystem"/>
</library:library> </library:library>