[GRASS-dev] [GRASS-SVN] r63227 - in grass/trunk/scripts: d.correlate d.out.file d.rast.leg d.redraw d.shadedmap d.to.rast d.vect.thematic d.what.rast d.what.vect

On Fri, Nov 28, 2014 at 4:43 AM, <svn_grass@osgeo.org> wrote:

+ env = grass.gisenv()
+ mon = env.get('MONITOR', None)
+ if not mon:
+ grass.fatal(_("No graphics device selected. Use d.mon to select
graphics device."))

Is this correct? I'm asking because d.shade(dmap) does not work in wxGUI
now; ends with this error. It was working before as well as the other d.*
commands, so the environment is set correctly it seems. Maybe the question
is what is the correct environment settings (both GRASS GIS and system).

On Sun, Nov 30, 2014 at 5:42 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Fri, Nov 28, 2014 at 4:43 AM, <svn_grass@osgeo.org> wrote:

+ env = grass.gisenv()
+ mon = env.get('MONITOR', None)
+ if not mon:
+ grass.fatal(_("No graphics device selected. Use d.mon to select
graphics device."))

Is this correct? I'm asking because d.shade(dmap) does not work in wxGUI
now; ends with this error. It was working before as well as the other d.*
commands, so the environment is set correctly it seems. Maybe the question
is what is the correct environment settings (both GRASS GIS and system).

Accidentally, I got error message which lead me to partial fix in r63306.

After running `d.mon cairo` in terminal, I get in wxGUI

Details: MONITOR variable defined, GRASS_RENDER_IMMEDIATE ignored

I guess that any of MONITOR in GRASS GIS environmental file and
GRASS_RENDER_IMMEDIATE is sufficient for running d.* commands. I think the
modules before r63227 which had the monitor check are not meant to run from
wxGUI directly; at least some of them are caught by GUI and executed
differently.

I think that the behavior I got in wxGUI might be a bug since nothing was
rendered but I don't understand what are the valid states of all variables.

Vaclav

http://trac.osgeo.org/grass/changeset/63306

Vaclav Petras wrote:

> + env = grass.gisenv()
> + mon = env.get('MONITOR', None)
> + if not mon:
> + grass.fatal(_("No graphics device selected. Use d.mon to select
> graphics device."))
>

Is this correct?

Not even remotely. I've removed the MONITOR checks from scripts in
r63315 (except for the ones which are wxGUI commands pretending to be
display commands; we still need to decide on a suitable prefix for
those).

--
Glynn Clements <glynn@gclements.plus.com>

On Mon, Dec 1, 2014 at 5:45 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Vaclav Petras wrote:

> + env = grass.gisenv()
> + mon = env.get('MONITOR', None)
> + if not mon:
> + grass.fatal(_("No graphics device selected. Use d.mon to select
> graphics device."))
>

Is this correct?

Not even remotely.

ok, sorry for the mess. See below for the reason of this attempt:

I've removed the MONITOR checks from scripts in
r63315 (except for the ones which are wxGUI commands pretending to be
display commands; we still need to decide on a suitable prefix for
those).

ok.

The issue is this:

GRASS 7.1.svn (nc_spm_08_grass7):~ > g.region rast=lsat7_2002_30
GRASS 7.1.svn (nc_spm_08_grass7):~ > d.correlate map=lsat7_2002_30,lsat7_2002_40
ERROR: No graphics device selected. Use d.mon to select graphics device.
Traceback (most recent call last):
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/scripts/d.correlate",
line 104, in <module>
    main()
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/scripts/d.correlate",
line 46, in main
    grass.write_command('d.text', color = 'black', size = 4, line = 1,
stdin = "CORRELATION")
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 483, in write_command
    return handle_errors(returncode, returncode, args, kwargs)
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 308, in handle_errors
    returncode=returncode)
grass.exceptions.CalledModuleError: Module run None ['d.text',
'color=black', 'line=1', 'stdin=CORRELATION', 'size=4'] ended with
error
Process ended with non-zero return code 1. See errors in the (error) output.

... looks rather ugly.
The same happens with several other d.* scripts. That's why I
attempted to catch this error. Please suggest how to do it right.

Markus

On Mon, Dec 1, 2014 at 12:00 PM, Markus Neteler <neteler@osgeo.org> wrote:

On Mon, Dec 1, 2014 at 5:45 PM, Glynn Clements <glynn@gclements.plus.com>
wrote:
> Vaclav Petras wrote:
>
>> > + env = grass.gisenv()
>> > + mon = env.get('MONITOR', None)
>> > + if not mon:
>> > + grass.fatal(_("No graphics device selected. Use d.mon to
select
>> > graphics device."))
>> >
>>
>> Is this correct?
>
> Not even remotely.

ok, sorry for the mess. See below for the reason of this attempt:

> I've removed the MONITOR checks from scripts in
> r63315 (except for the ones which are wxGUI commands pretending to be
> display commands; we still need to decide on a suitable prefix for
> those).

ok.

The issue is this:

GRASS 7.1.svn (nc_spm_08_grass7):~ > g.region rast=lsat7_2002_30
GRASS 7.1.svn (nc_spm_08_grass7):~ > d.correlate
map=lsat7_2002_30,lsat7_2002_40
ERROR: No graphics device selected. Use d.mon to select graphics device.
Traceback (most recent call last):
  File
"/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/scripts/d.correlate",
line 104, in <module>
    main()
  File
"/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/scripts/d.correlate",
line 46, in main
    grass.write_command('d.text', color = 'black', size = 4, line = 1,
stdin = "CORRELATION")
  File
"/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 483, in write_command
    return handle_errors(returncode, returncode, args, kwargs)
  File
"/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 308, in handle_errors
    returncode=returncode)
grass.exceptions.CalledModuleError: Module run None ['d.text',
'color=black', 'line=1', 'stdin=CORRELATION', 'size=4'] ended with
error
Process ended with non-zero return code 1. See errors in the (error)
output.

The d.correlate script does not check if the modules it is calling were

successful. It is not limited to not set MONITOR problem, the errors can
potentially happen from other reasons too. The standard way how to solve it
is to have all module calls in a try-except (one big or more smaller ones)
and do whatever is necessary in except (e.g. exit). The except should catch
CalledModuleError and perhaps use its message or better module name (not
implemented yet).

... looks rather ugly.
The same happens with several other d.* scripts. That's why I
attempted to catch this error. Please suggest how to do it right.

Markus

On Mon, Dec 1, 2014 at 11:45 AM, Glynn Clements <glynn@gclements.plus.com>
wrote:

(except for the ones which are wxGUI commands pretending to be
display commands; we still need to decide on a suitable prefix for
those).

We should proceed with this. I still don't understand which options are the
one pretending. I considered all modules related to display control to be
d.*. You are suggesting that only the ones which are drawing should be d.*.
Does this apply to d.mon, d.colorlist, d.save, d.zoom, d.erase and some
others (if they would get to G7)?

Here are all the existing d.* commands in G 7.0.0 svn:

d.colorlist
d.colortable
d.correlate
d.erase
d.font
d.fontlist
d.geodesic
d.graph
d.grid
d.his
d.histogram
d.info
d.labels
d.legend
d.linegraph
d.mon
d.northarrow
d.out.file
d.path
d.polar
d.profile
d.rast
d.rast.arrow
d.rast.edit
d.rast.leg
d.rast.num
d.redraw
d.rgb
d.rhumbline
d.shadedmap
d.text
d.thematic.area
d.title
d.to.rast
d.vect
d.vect.chart
d.vect.thematic
d.what.rast
d.what.vect
d.where

At least these are not doing the drawing as far as I know:

d.colorlist
d.correlate
d.erase
d.font
d.fontlist
d.info
d.mon
d.northarrow
d.out.file
d.redraw
d.to.rast

Markus Neteler wrote:

The issue is this:

GRASS 7.1.svn (nc_spm_08_grass7):~ > g.region rast=lsat7_2002_30
GRASS 7.1.svn (nc_spm_08_grass7):~ > d.correlate map=lsat7_2002_30,lsat7_2002_40
ERROR: No graphics device selected. Use d.mon to select graphics device.
Traceback (most recent call last):
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/scripts/d.correlate",
line 104, in <module>
    main()
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/scripts/d.correlate",
line 46, in main
    grass.write_command('d.text', color = 'black', size = 4, line = 1,
stdin = "CORRELATION")
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 483, in write_command
    return handle_errors(returncode, returncode, args, kwargs)
  File "/home/neteler/software/grass71/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 308, in handle_errors
    returncode=returncode)
grass.exceptions.CalledModuleError: Module run None ['d.text',
'color=black', 'line=1', 'stdin=CORRELATION', 'size=4'] ended with
error
Process ended with non-zero return code 1. See errors in the (error) output.

I can't reproduce the problem. And I'm not even sure how d.text can
exit with a non-zero return code without printing any error message.

In any case, display commands don't need any "graphics device" to be
selected.

--
Glynn Clements <glynn@gclements.plus.com>

On Tue, Dec 2, 2014 at 5:09 PM, Glynn Clements <glynn@gclements.plus.com>
wrote:

Markus Neteler wrote:

> The issue is this:
>
> GRASS 7.1.svn (nc_spm_08_grass7):~ > g.region rast=lsat7_2002_30
> GRASS 7.1.svn (nc_spm_08_grass7):~ > d.correlate
map=lsat7_2002_30,lsat7_2002_40
> ERROR: No graphics device selected. Use d.mon to select graphics device.
> Traceback (most recent call last):
> ...
> grass.exceptions.CalledModuleError: Module run None ['d.text',
> 'color=black', 'line=1', 'stdin=CORRELATION', 'size=4'] ended with
> error
> Process ended with non-zero return code 1. See errors in the (error)
output.

I can't reproduce the problem. And I'm not even sure how d.text can
exit with a non-zero return code without printing any error message.

I can reproduce it. Are you sure you don't have MONITOR or
GRASS_RENDER_IMMEDIATE (or any other if it matters) set? I start GRASS
session (without any special shell environment) and I get it.

The error is the beginning, r.text is printed first (that's ERROR:... I
think), then the error from the main process is printed (Traceback....).

I think the solution is try-except or calling the function(s) with with
secret `errors` parameter set to 'exit'. The later is usually not the ideal
solution but it might be appropriate for some calls in d.* scripts. The
issue is that with errors='exit' you cannot provide the user with failed
module name, so then the context of the error message might be unclear.

Vaclav Petras wrote:

> > The issue is this:
> >
> > GRASS 7.1.svn (nc_spm_08_grass7):~ > g.region rast=lsat7_2002_30
> > GRASS 7.1.svn (nc_spm_08_grass7):~ > d.correlate
> map=lsat7_2002_30,lsat7_2002_40
> > ERROR: No graphics device selected. Use d.mon to select graphics device.
> > Traceback (most recent call last):
> > ...
> > grass.exceptions.CalledModuleError: Module run None ['d.text',
> > 'color=black', 'line=1', 'stdin=CORRELATION', 'size=4'] ended with
> > error
> > Process ended with non-zero return code 1. See errors in the (error)
> output.
>
> I can't reproduce the problem. And I'm not even sure how d.text can
> exit with a non-zero return code without printing any error message.

I can reproduce it. Are you sure you don't have MONITOR or
GRASS_RENDER_IMMEDIATE (or any other if it matters) set? I start GRASS
session (without any special shell environment) and I get it.

The error is the beginning, r.text is printed first (that's ERROR:... I
think), then the error from the main process is printed (Traceback....).

Er, right; I got confused by the fact that the script changes used
exactly the same error message as d.text (which is a leftover from
6.x).

The issue has been fixed in r63361. The issue was first introduced in
r46984 and incorrectly "fixed" in r46999.

In GRASS 7, it isn't (or shouldn't have been) necessary to set
GRASS_RENDER_IMMEDIATE. This variable only exists to choose a driver
other than the default (cairo if supported, otherwise PNG).

I think the solution is try-except or calling the function(s) with with
secret `errors` parameter set to 'exit'.

No. There's no point in catching exceptions if you aren't going to
handle them. If we want to avoid the tracebacks, we should find a
solution which works globally, not require each and every script to
manually handle exceptions from each and every called module.

--
Glynn Clements <glynn@gclements.plus.com>

On Wed, Dec 3, 2014 at 12:54 PM, Glynn Clements <glynn@gclements.plus.com>
wrote:

Vaclav Petras wrote:

> > > The issue is this:
> > >
> > > GRASS 7.1.svn (nc_spm_08_grass7):~ > g.region rast=lsat7_2002_30
> > > GRASS 7.1.svn (nc_spm_08_grass7):~ > d.correlate
> > map=lsat7_2002_30,lsat7_2002_40
> > > ERROR: No graphics device selected. Use d.mon to select graphics
device.
> > > Traceback (most recent call last):
> > > ...
> > > grass.exceptions.CalledModuleError: Module run None ['d.text',
> > > 'color=black', 'line=1', 'stdin=CORRELATION', 'size=4'] ended with
> > > error
> > > Process ended with non-zero return code 1. See errors in the (error)
> > output.
> >
> > I can't reproduce the problem. And I'm not even sure how d.text can
> > exit with a non-zero return code without printing any error message.
>
>
> I can reproduce it. Are you sure you don't have MONITOR or
> GRASS_RENDER_IMMEDIATE (or any other if it matters) set? I start GRASS
> session (without any special shell environment) and I get it.
>
> The error is the beginning, r.text is printed first (that's ERROR:... I
> think), then the error from the main process is printed (Traceback....).

Er, right; I got confused by the fact that the script changes used
exactly the same error message as d.text (which is a leftover from
6.x).

The issue has been fixed in r63361. The issue was first introduced in
r46984 and incorrectly "fixed" in r46999.

In GRASS 7, it isn't (or shouldn't have been) necessary to set
GRASS_RENDER_IMMEDIATE. This variable only exists to choose a driver
other than the default (cairo if supported, otherwise PNG).

> I think the solution is try-except or calling the function(s) with with
> secret `errors` parameter set to 'exit'.

No. There's no point in catching exceptions if you aren't going to
handle them.

I agree. If it is not probable that the module will fail, I think you don't
have to do try-except. In case of error you get the traceback which is
great because it will help you identify the problem (and for example handle
the errors in a better way if the original premise about error not being
probable was wrong). But it also depends on what you call handling.

If we want to avoid the tracebacks, we should find a
solution which works globally,

I'm not sure if we want to avoid tracebacks because hiding traceback does
not mean that the error is not there and you might be just loosing valuable
info about the place of the error. However, we have already
set_raise_on_error(), so this would be similar.

But I'm convinced that exceptions (and tracebacks) are good default because
this is how Python works and it provides the largest amount of information.

not require each and every script to
manually handle exceptions from each and every called module.

This would be bad but I think if script author wants one big try-except

for several module calls I think that it is OK if a message saying what
happened from the point of view of the script is provided.

--

Glynn Clements <glynn@gclements.plus.com>