effect.cpp / script.cpp: Rethink handling of stderr for custom gui extensions
Context
Extensions providing a custom gui can be marked as those in the inx file by setting implements-custom-gui = true
. This triggers two things:
- The work in progress dialog is not shown (this makes sense since the extension shows its own dialog)
- Any output to stderr is not shown when the extension has finished.
effect.cpp:
if (child->attribute("implements-custom-gui") && !strcmp(child->attribute("implements-custom-gui"), "true")) {
_workingDialog = false;
ignore_stderr = true;
}
script.cpp:
Glib::ustring stderr_data = fileerr.string();
if (!stderr_data.empty() && !ignore_stderr) {
if (INKSCAPE.use_gui()) {
showPopupError(stderr_data, Gtk::MESSAGE_INFO,
_("Inkscape has received additional data from the script executed. "
"The script did not return an error, but this may indicate the results will not be as expected."));
} else {
std::cerr << "Script Error\n----\n" << stderr_data.c_str() << "\n----\n";
}
}
Problem formulation
Let's have a look at the extension code of a typical extension using a custom gui (super simplified):
import required_stuff
from extension import Extension
if __name__ == "__main__":
try:
effect = Extension()
effect.run()
except ... :
... Error Handling ...
We observe the following:
- You can implement the
Extension
class such that it handles all errors in a proper way and displays corresponding messages to the user. That's fine. - Even if something is not handled by the Extension class we can handle this error in the outer except block.
- However, what is handled in this except block cannot be displayed to the user. We can write it to a log file, but, since stderr is not processed, the extension wouldn't show up and the user has the experience "Nothing happened".
- The user could search for the log file for more information but this is not very smart for an average user.
Solution
My proposal is to add the possibility to show stderr after the extension closes even for custum-gui extensions. Maybe with an additional optional keyword show-stderr-after-exit
or sth. like this. In the documentation it can be stated that the extension author has to make sure that stderr is emptied after his extension has completed, otherwise it will be shown to the user. The default value of this new key is false
, so we keep the old behavior.
Background
As the author of an extension using a custom-gui I am often confronted with the problem that the GUI framework is not properly set-up on the users's system. In this scenario the extension (and also the Inkscape Extensio manager, btw) does not show up. Most users who open an issue need to be guided to the log file. It costs time to explain this again and again, and the log file needs to be searched for errors. Presenting the essential problems to the user using the Inkscape error dialog in these scenarios would be great.
Questions
Do I miss sth. here? If not, I could do an example implementation as described above and open a merge request.