During development, I introduced an error to my extension that causes gnome-shell
to crash upon trying to load the extension with the following rather broadly phrased error message:
Execution of main.js threw exception: JS_EvaluateScript() failed
It would be nice to be able to test an extension while
Is this possible?
I already searched through the gnome-shell
and gjs
repos to try and find a way to improve the error message. I found three call sites that emit an error with prefix Execution of main.js threw exception:
but I could not find the actual call to JS_EvaluateScript
in GJS.
I also tried running my extension with gjs
like this:
gjs -I /usr/lib/gnome-shell extension.js
But gjs
complains about
Typelib file for namespace 'St' (any version) not found @extension.js:3:7
although St-1.0.typelib
is indeed located in /usr/lib/gnome-shell
I know that I can use LookingGlass to evaluate some JS strings.
I know that the error was caused by calling into native code (St
) with invalid arguments.
The JS_EvaluateScript
in that error message is outdated, and not particularly helpful. It will be improved in the upcoming GNOME 3.28.
The code you are looking for (with the improved error message) is here and you can see there is a call to gjs_log_exception()
right after setting the error that is returned to GNOME Shell. You should be able to find that exception in the system journal (sudo journalctl -xb
), even on your current version of GNOME.
There's always a risk of crashing the shell, since native code may crash if you give it wrong input. We aim to prevent crashes in GJS itself assuming native code is well-behaved. Once you isolate the problem, if it seems like something GJS could prevent, please make a bug report at https://gitlab.gnome.org/GNOME/gjs.
This question and answer might help to test your extension in a separate process, if you put the following code at the top of your file before you import St
:
const GIRepository = imports.gi.GIRepository;
GIRepository.Repository.prepend_search_path("/usr/lib/gnome-shell");
GIRepository.Repository.prepend_library_path("/usr/lib/gnome-shell");
However, it depends on what you are doing in your extension. Many extensions modify parts of GNOME Shell, and so if you run outside of GNOME Shell then they won't work.