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

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):
}}}

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.

Do you think it is a bad idea?

Best regards

Pietro

On 3 July 2014 17:35, Pietro <peter.zamb@gmail.com> wrote:

Dear devs,

Hi,

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):
}}}

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.

Do you think it is a bad idea?

If it is possible without create problems I think it is a good idea...

Best regards

Pietro

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

On Fri, Jul 4, 2014 at 8:53 AM, Luca Delucchi <lucadeluge@gmail.com> wrote:

On 3 July 2014 17:35, Pietro <peter.zamb@gmail.com> wrote:

What do you think if we unify all our custom exceptions in one common file?
Just to avoid code repetitions and help consistency.

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.

Do you think it is a bad idea?

If it is possible without create problems I think it is a good idea...

yes, I think so.

Personally I think that the exception should stay outside the
grass.script directory, because they are general and are also used in
the grass (gui/lib) libraries.
So If there are not opponents I would create an exception file in
/lib/python/exceptions.py with all the definitions.

Let me know.

Pietro

On Thu, Jul 3, 2014 at 11:35 AM, Pietro <peter.zamb@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
necessary.

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@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Hi Vaclav,

On Mon, Jul 7, 2014 at 2:57 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

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

What do you think if we unify all our custom exceptions in one common
file? [snip]
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):
}}}

However, some of them should stay where they are. [snip]

ok, so I'm going to move to grass.exceptions the following definitions:

- lib/python/pygrass/messages/__init__.py:21:class FatalError(Exception):
- lib/python/pygrass/errors.py:19:class ParameterError(Exception):
- lib/python/pygrass/errors.py:23:class FlagError(Exception):
- lib/python/temporal/abstract_dataset.py:26:class
ImplementationError(Exception):
- lib/python/temporal/temporal_algebra.py:655:class FatalError(Exception):
- lib/python/script/core.py:50:class ScriptError(Exception):
- gui/wxpython/wxgui.py:86:class Usage(Exception):

so these exceptions will stay where they are:

- lib/python/pydispatch/errors.py:4:class DispatcherError(Exception):
- lib/python/ctypes/ctypesgencore/parser/lex.py:46:class LexError(Exception):
- lib/python/ctypes/ctypesgencore/parser/yacc.py:87:class YaccError(Exception):
- gui/wxpython/core/gcmd.py:156:class GException(Exception):

Any concern?

Pietro