RoboFont makes scripting more accesible to designers; designers who get into scripting quickly become familiar with sotware errors.
This page offers some tips to help you look for answers and solve errors by yourself.
In order to fix an error, we must first find it in the source code. Every error message includes a traceback which displays a stack of all nested function calls during program execution. Thanks to the traceback we can see where the error originated, and where the failure actually occurred.
Error and Traceback example
Here’s a simple faulty script which raises an error:
def aFunction(): anotherFunction() def anotherFunction(): aThirdFunction() aFunction()
Traceback (most recent call last): File "<untitled>", line 7, in <module> File "<untitled>", line 2, in aFunction File "<untitled>", line 5, in anotherFunction NameError: name 'aThirdFunction' is not defined
The traceback tells the story of the error:
aThirdFunctionis not defined, so a
Getting errors while writing your own scripts is quite common, and it’s part of the process. As your script evolves, you can add conditions and checks to avoid triggering predicatable errors.
For example, let’s say you have a script that does something to the selected glyphs in the current font:
f = CurrentFont() for glyphName in f.selection: print(glyphName)
If you try to run this script without having a font open, you will get an error:
Traceback (most recent call last): File "<untitled>", line 2, in <module> TypeError: object of type 'NoneType' has no len()
A more robust script could first check if a font is open, and if not, print out a message to the user while avoiding the error. We can also warn the user if the selection is empty:
f = CurrentFont() # make sure we have an open font if f is not None: # make sure at least one glyph is selected if len(f.selection): # do something to selected glyphs for glyphName in f.selection: print(glyphName) # no glyph selected else: print('please select at least one glyph!') # no font open else: print('please open a font first!')