ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > FARR Plugins and Aliases

FScript Javascript SDK - Write FARR plugins in javascript and more.

<< < (14/17) > >>

ewemoa:
I am starting to experiment more with writing plugins using Python.

My experience so far is that I do not know how to become aware of at least one type of runtime difficulty.  Specifically, I do not know that the plugin has aborted execution due to an exception being raised.  Tracking down relevant lines in the source code can become a chore with no hints!

Does any one have any ideas (other than wrap every function call body in try/except) about how to be alerted about runtime exceptions?  Any chance that FScript could make a stacktrace available (or may be it does already and I don't know where to look)?

For comparison, when this type of thing occurs for a JavaScript plugin, I am alerted by my local installation of MS Script Debugger...I went looking for something similar for Python, but so far I have not been successful in locating anything.

I hope someone has some good ideas regarding this situation :)

Edit: catch -> except ... oops ;)

ewemoa:
At the moment, I'm taking the wrap function bodies approach -- as an example, an onInit might look like:


--- Code: Python ---def onInit(currentDirectory):  try:    # XXX    1 / 0  except:    type, value, tb = sys.exc_info()    FARR.setStrValue("DisplayAlertMessage", repr(traceback.format_exception(type, value, tb)))
This is assuming something like the following also in an appropriate location in the code:


--- Code: Python ---import sys, traceback
DisplayAlertMessage is a bit tight on space, so I'm considering alternatives.  Perhaps bring up some browser window?  It'd be neat to display the stack trace, but also perhaps load the source for the file with the problem and highlight the problematic line.  Mmm, how to do that...

Doing this for each function sounds painful so I'm thinking of writing some code to appropriately "instrument" certain functions -- may be just the plugin entry points.  This code could then be placed so that it runs when the plugin is first loaded.

Any reflections?

ewemoa:
I've made something using Python's decorators.  I have the following code near the beginning of a plugin:


--- Code: Python ---import sys, traceback, pprint # "advice" -- quick-and-dirty wrapping/instrumenting code## to use, place @around before a function definition line.# for example, for a function f:##   @around#   def f(arg1):#     print arg1## based on code at:#   http://livingcode.org/2009/aspect-oriented-pythondef around(fn):  def wrapped(*args, **kws):    try:      return fn(*args, **kws)    except:      import pprint      xtype, value, tb = sys.exc_info()      trace = traceback.format_exception(xtype, value, tb)      tracestr = pprint.pformat(trace)      efname = plugindir() + "\\exception.txt"      f = open(efname, "w")      f.write(tracestr)      f.close()      FARR.setStrValue("launch", "notepad.exe " + efname)  return wrapped
Then example usage for onInit might be:


--- Code: Python ---@arounddef onInit(currentDirectory):  FARR.setStrValue("DisplayAlertMessage", "Know any perfect numbers?")  # XXX  1 / 0
That is, just place "@around" on the line preceding the first line of a function definition -- assuming you want the function in question "wrapped".

The basic idea seems ok -- but using "launch" w/ "showhtml" isn't working out so well for plugin reloads.  Looks like FARR quickly goes on to display the result of the plugins reloading so I don't get enough time to read the stack trace...

Edit: It's a bit ugly, but now the code writes exception information to a temporary file within the plugin directory and opens it using notepad.

mouser:
Do we have a python and ruby example somewhere?

ecaradec:
Yep, debugging in python or ruby suck. the activescript binding of python and ruby is limited to running script but not debugging them, and the debugging support is required to get correct error lines, etc... May be there is somewhere a debuggable active script implementation of python ?
Once you have a good understanding on what FARR pass as parameters and order of methods call, you can try running plugins standalone and integrate them as FARR plugin at the end. Not the solution I'd like but it helps.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version