[GRASS-dev] Unify python GRASS defined exception in one common file

Vaclav Petras wenzeslaus at gmail.com
Mon Jul 7 05:57:30 PDT 2014

On Thu, Jul 3, 2014 at 11:35 AM, Pietro <peter.zamb at gmail.com> wrote:

> Dear devs,
> What do you think if we unify all our custom exceptions in one common file?
> Just to avoid code repetitions and help consistency.
> Looking into the code I found the following custom exceptions:
> {{{
> $ grep --color=auto
> --exclude-dir={.svn,.git,.OBJ,locale,dist.x86_64-unknown-linux-gnu}
> -IrnE "class\s\w+\(Exception\)\:"
> lib/python/pygrass/messages/__init__.py:21:class FatalError(Exception):
> lib/python/pygrass/errors.py:11:class AbstractError(Exception):
> lib/python/pygrass/errors.py:19:class ParameterError(Exception):
> lib/python/pygrass/errors.py:23:class FlagError(Exception):
> lib/python/pydispatch/errors.py:4:class DispatcherError(Exception):
> lib/python/temporal/abstract_dataset.py:26:class
> ImplementationError(Exception):
> lib/python/temporal/temporal_algebra.py:655:class FatalError(Exception):
> lib/python/ctypes/ctypesgencore/parser/lex.py:46:class LexError(Exception):
> lib/python/ctypes/ctypesgencore/parser/yacc.py:87:class
> YaccError(Exception):   pass
> lib/python/script/core.py:50:class ScriptError(Exception):
> gui/wxpython/core/gcmd.py:156:class GException(Exception):
> gui/wxpython/wxgui.py:86:class Usage(Exception):
> }}}
I think that generally they should be in one file/module. These should
inherit from a custom GrassError (if they are errors) but his is not

However, some of them should stay where they are. Namely the ones which are
used to control more-standard flow of the program (which is the case of
Usage from wxgui.py) and the ones which are specific to some 3rd party code
(such as DispatcherError from pydispatch). In other words, if the
exceptions are not reusable (because they are highly specialized) or it is
not clear what are the use cases of the exaction (i.e. the same exception
would be used at different occasions without common pattern), they should
stay where they are.

On the other hand, I can see that Usage, or differently named exception
with same meaning, could be used in general.

Perhaps we could create a new file in grass.script.errors or
> grass.script.exceptions, or outside script so something like
> grass.errors or grass.exceptions.
> It seems that error is more used for exceptions which are errors. Python
has package/module `exceptions`, some packages have module errors.
Exceptions sounds more general.

Do you think it is a bad idea?
> Best regards
> Pietro
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140707/63968a92/attachment.html>

More information about the grass-dev mailing list