×
Namespaces

Variants
Actions

Archived:Enhancing runtime error detection for PySymbian applications

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Article
Created: marcelobarrosalmeida (22 Nov 2009)
Last edited: hamishwillee (31 May 2013)

Contents

Introduction

During the development phase it is common to execute all PySymbian applications from the Python shell. The option Run script is responsible to select and launch your application. It is possible to use the console as well, on the phone or remote, via bluetooth or WiFi.

However, when you decide to deploy your program using some sis executable, a new bunch of problems may arise. In general these problems are related to missing modules, wrong paths in sys.path, different phone models and so on.

In this article it will be proposed a simple strategy to collect runtime errors for PySymbian applications. Even final users will be able to report problems using the proposed strategy.

Proposed strategy

The debug strategy is based on collecting all necessary information from phone and exception data after a failure, creating a new user interface and allowing the user to report them easily.

The solution skeleton is presented below:

try:
# Put you startup code here.
# For instance, import your module and run it.
# import my_module
# my_module.startup()
pass
except Exception, e:
# Oops, something wrong. Report problems to user
# and ask him/her to send them to you.
import appuifw
import traceback
import sys
import e32
 
# Collecting call stack info
e1,e2,e3 = sys.exc_info()
call_stack = unicode(traceback.format_exception(e1,e2,e3))
 
# Creating a friendly user message with exception details
new_line = u"\u2029"
err_msg = u"This programs was unexpectedly closed due to the following error: "
err_msg += unicode(repr(e)) + new_line
err_msg += u"Please, copy and past the text presented here and "
err_msg += u"send it to email@server.com. "
err_msg += u"Thanks in advance and sorry for this inconvenience." + new_line*2
err_msg += u"Call stack:" + new_line + call_stack
 
# Small PySymbian application
lock = e32.Ao_lock()
appuifw.app.body = appuifw.Text(err_msg)
appuifw.app.body.set_pos(0)
appuifw.app.menu = [(u"Exit", lambda: lock.signal())]
appuifw.app.title = u"Error log"
lock.wait()

Basically, the exception handler data is collected and presented to the user using a new user interface with menu and Text() as main body. For instance, suppose your main program is just the following code snippet:

#...
try:
import camera
camera.take_photo(camera.RGB32) # error: invalid mode
except Exception, e:
#...

The following message will be presented to the user:

This programs was unexpectedly closed due to the following error: AttributeError("'module' object has no attribute 'RGB32'",)
Please, copy and past the text presented here and send it to email@server.com. Thanks in advance and sorry for this inconvenience.

Call stack:
['Traceback (most recent call last):\n', '  File "e:\\python\\demo.py", line 7, in <module>\n camera.take_photo(camera.RGB32)\n', "AttributeError: 'module' object has no attribute 'RGB32'\n"]

MBA base skel runtime err.png

Enhancements

This skeleton may be improved with some new actions. For instance, SMS/MMS messages could be created and sent to program's author using messaging module or you could take a screenshot using graphics module. The modified program is below, followed by a screenshot of the received message.

try:
# Put you startup code here.
# For instance, import your module and run it.
# import my_module
# my_module.startup()
import camera
camera.take_photo(camera.RGB32) # error: invalid mode
except Exception, e:
# Oops, something wrong. Report problems to user
# and ask him/her to send them to you.
import appuifw
import traceback
import sys
import e32
 
# Collecting call stack info
e1,e2,e3 = sys.exc_info()
call_stack = unicode(traceback.format_exception(e1,e2,e3))
 
# Creating a friendly user message with exception details
new_line = u"\u2029"
err_msg = u"This programs was unexpectedly closed due to the following error: "
err_msg += unicode(repr(e)) + new_line
err_msg += u"Please, copy and past the text presented here and "
err_msg += u"send it to email@server.com. "
err_msg += u"Thanks in advance and sorry for this inconvenience." + new_line*2
err_msg += u"Call stack:" + new_line + call_stack
 
def send_sms():
import messaging
msg = appuifw.app.body.get()
messaging.sms_send("+5516xxxxxxxx",msg) # put your phone here
appuifw.note(u"A message was created and sent. Thanks a lot.","info")
 
def save_screenshot():
import graphics
ss = graphics.screenshot()
ss.save(u"e:\\screenshot.png")
appuifw.note(u"Screenshot saved in e:\\ ","info")
 
# Small PySymbian application
lock = e32.Ao_lock()
appuifw.app.body = appuifw.Text(err_msg)
appuifw.app.body.set_pos(0)
appuifw.app.menu = [(u"Send report via SMS",send_sms),
(u"Save screenshot",save_screenshot),
(u"Exit", lambda: lock.signal())]
appuifw.app.title = u"Error log"
lock.wait()

MBA sms runtime err.png

Conclusion

In this article it was presented a strategy to help users to report runtime problems in PySymbian applications. Developers may use this code snippet to create better error reports automatically, decreasing your debug time and motivating the bug report.

This page was last modified on 31 May 2013, at 04:03.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×