Bug 170564 - import error message from scriptforge is confusing
Summary: import error message from scriptforge is confusing
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
25.8.4.2 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2026-02-02 03:17 UTC by tripod312
Modified: 2026-03-31 09:44 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
error message (29.59 KB, image/png)
2026-02-02 03:21 UTC, tripod312
Details
calc ods (25.78 KB, application/vnd.oasis.opendocument.spreadsheet)
2026-02-02 03:23 UTC, tripod312
Details
python macro (393 bytes, text/x-python)
2026-02-02 03:24 UTC, tripod312
Details
stacktrace (42.12 KB, image/png)
2026-02-02 21:46 UTC, Werner Tietz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tripod312 2026-02-02 03:17:16 UTC
Description:
I wrote macro in calc file,wrote python scrpit in macro directory.  
I executed the script add got error.  
error message from scriptforge is "NOSCRIPTERROR".
But the script exists.  
Actual error is that the script imports library which is not exists.

Steps to Reproduce:
1.create ods file and put macro bellow

Sub Main
	GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
	session = CreateScriptService("Session")
	sRange=session.ExecutePythonScript(session.SCRIPTISPERSONAL, "util.py$str_format", "{}{}:{}{}","A",1,"B",10) 
	print(sRange)
End Sub

2.create util.py
C:\Users\_USER_\AppData\Roaming\LibreOffice\4\user\scripts\python\util.py

import not_present  #error

def str_format(fmt,*params):
    s = fmt.format(*params)
    return s

3.run macro

Actual Results:
error message from scriptforge is bellow

Error NOSCRIPTERROR x
A Library: ScriptForge
Service: Session
Method: ExecutePythonScript
Arguments: [Scope], Script, argO[, arg1]
A serious error has been detected in your code on argument : « Script ».
|
The requested Python script could not be located in the given libraries and
modules.
« Scope » = user
« Script » = util.py$strformat
THE EXECUTION IS CANCELLED.
Do you want to receive more information about the ‘ExecutePythonScript"
method ?
dom | DZD,


Expected Results:
error message from scriptforge is "IMPORTERROR".


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 25.8.4.2 (X86_64)
Build ID: 290daaa01b999472f0c7a3890eb6a550fd74c6df
CPU threads: 12; OS: Windows 11 X86_64 (build 26200); UI render: Skia/Raster; VCL: win
Locale: ja-JP (ja_JP); UI: ja-JP
Calc: threaded
Comment 1 tripod312 2026-02-02 03:21:11 UTC
Created attachment 205303 [details]
error message
Comment 2 tripod312 2026-02-02 03:23:08 UTC
Created attachment 205304 [details]
calc ods
Comment 3 tripod312 2026-02-02 03:24:06 UTC
Created attachment 205305 [details]
python macro
Comment 4 Werner Tietz 2026-02-02 21:17:45 UTC
Cannot reproduce the issue!

Nevertheless, I would suggest avoiding ScriptForge and instead using:

```
sub call_python
    provider = thisComponent.getScriptprovider()
    script = provider.getScript("vnd.sun.star.script:util.py$str_format?language=Python&location=user")    
    args = array("{}{}:{}{}","A",1,"B",10)
    print script.invoke(args, array(), array())
end sub
```
Comment 5 Werner Tietz 2026-02-02 21:46:36 UTC
Created attachment 205332 [details]
stacktrace

errormessage on provoked ImportError from python
Comment 6 Jean-Pierre Ledure 2026-03-31 09:44:36 UTC
The ExecutePythonScript() method uses in the background the same UNO interfaces as the example in comment#4, i.e.
- script = provider.getScript()
- script.invoke()

The error message which is considered in this bug report is related to the execution of getScript().
The major reasons for getScript() being unsuccessful are reflected in the message: either the file does not exist or the called [def] function is not found.

The case in the example is different: it is a *compile* error: the import statement is indeed executed at module loading.

It is rather unusual to run a Python script from Basic while it even does not compile stand alone.

Compare with next variant. If you move the import statement to inside the function, the import is delayed up to the invoke() method. It fails - obvously - too. But it is now an *execution* error that is reported in detail in the error message displayed to the user, as would any other run-time error.

The distinction in error reporting was made deliberately.
It can nevertheless be reviewed.
But, is it really relevant and useful to review it ?

More comments welcome.

Thanks for reporting the bug.