Kim Besson wrote:
I have python script where I try to catch, as much as possible all errors,
in order to avoid "abrupt" ERRORS from the script.
for instance I do this for grass.run_command:
p=grass.run_command("i.group", group=group_name, subgroup="subgroup", input=
input)
if p!=0:
grass.fatal(_("ERROR MESSAGE"))
but I'm not being able to do this for grass.mapcalc. has anyone any
suggestion or tip on how to do this for grass.mapcalc?
You could probably replace the imported fatal() function with your own
function, e.g.:
import grass.script as grass
...
def my_fatal(msg):
...
grass.raster.fatal = my_fatal
Beyond that, we should probably think about how to deal with errors in
the Python scripting library. I.e. whether to raise Python exceptions,
return status codes, call fatal(), etc. Right now, each function does
as it pleases; there isn't any consistency.
--
Glynn Clements <glynn@gclements.plus.com>
Hi,
2010/10/30 Glynn Clements <glynn@gclements.plus.com>:
Beyond that, we should probably think about how to deal with errors in
the Python scripting library. I.e. whether to raise Python exceptions,
return status codes, call fatal(), etc. Right now, each function does
as it pleases; there isn't any consistency.
r44086 helps a bit?
error() raise ScriptException() by default. If you call
raise_on_error(False) then error() prints error message via `g.message
-e`.
Martin
--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa
Martin Landa wrote:
> Beyond that, we should probably think about how to deal with errors in
> the Python scripting library. I.e. whether to raise Python exceptions,
> return status codes, call fatal(), etc. Right now, each function does
> as it pleases; there isn't any consistency.
r44086 helps a bit?
error() raise ScriptException() by default. If you call
raise_on_error(False) then error() prints error message via `g.message
-e`.
There's still the question of when to generate errors. E.g. should
run_command() just return the exit code or should it generate an error
if the exit code is non-zero? If it raises an exception, the actual
exit code should be retrievable from the exception object.
--
Glynn Clements <glynn@gclements.plus.com>