Friday, December 29, 2006

Where is that error coming from?

If a graphical user interface (GUI) has been properly coded, any user error condition will be reported to the user as a dialog similar to...



This is great for the end user because it does not look as cryptic as...



...
but it is a bit of a nightmare to debug if you want to find out where in the code this condition was raised. The cryptic dialog would have been nice because then you could "Show traceback" and continue your investigation from there.

Well, you can also force a traceback with the "nicer" error message if you have access to a MagikSF prompt (typically through emacs). You need to put a !traceback!() call in basic_window.show_alert() to get a look at the callstack to find out where the problem was. Unfortunately, this method is not shipped with CST 4.0, so you will need to do some Magik to force a traceback.

(By the way, the topic of shipped/unshipped code and the Open Source "movement" in the Smallworld community will be covered soon in another article).


1. save the original basic_window.show_alert() method's procedure

MagikSF> orig_proc <<
basic_window.method(:show_alert|()|).value
$


2. temporarily redefine the method to show a traceback

MagikSF> _method basic_window.show_alert(_gather args)
!traceback!(!terminal!)
_endmethod
$


3. Redo the GUI action that cause the user error dialog in the first place. Because of how we redefined the :show_alert() method above, we will not see the error dialog, but we will see the traceback at the command line. Use that traceback to investigate the problem further.

4. revert the basic_window.show_alert() method to its original procedure

MagikSF> basic_window.method(:show_alert|()|).
value << orig_proc
$


As always, if you have any questions or comments about a post, please feel free to e-mail me or reply with a comment to this post.

Now, back to digging out from another blizzard :)

2 comments:

Roger Neal said...

There is a simpler way to do this.

The Development Tools application (available at 4.1) has a toggle labelled
'Show User Tracebacks'
This switches between the two types of dialog i.e. with and without a traceback option.

Alternatively you can simply set model.enable_user_error_tracebacks? to true or false.
This can be done from the command line.

Alfred Sawatzky said...

Hi Roger. Thank you for that clarification. I have posted an update. Any clarifications or comments you can make to this or other posts will only help to improve the understanding of the Smallworld product. And anything that helps improve Smallworld knowledge is good for all of us that are associated with this product suite.