[GRASS-dev] [GRASS GIS] #2326: Command functions in grass.script.core miss a correct error reporting

GRASS GIS trac at osgeo.org
Tue Nov 11 10:34:14 PST 2014


#2326: Command functions in grass.script.core miss a correct error reporting
--------------------------------+-------------------------------------------
 Reporter:  wenzeslaus          |       Owner:  grass-dev@…              
     Type:  enhancement         |      Status:  new                      
 Priority:  major               |   Milestone:  7.1.0                    
Component:  Python              |     Version:  svn-trunk                
 Keywords:  script, exceptions  |    Platform:  All                      
      Cpu:  Unspecified         |  
--------------------------------+-------------------------------------------

Comment(by wenzeslaus):

 Replying to [comment:33 neteler]:
 > While no crash occurs any more with r62705, it doesn't stop any longer
 on error:
 >
 {{{
 GRASS 7.1.svn (nc_spm_08_grass7):~ > r.basin map=elevation prefix=my_basin
 coord=637500.0,221750.0 dir=/tmp/bla threshold=1000 --o
 ...
 WARNING: 'r.width.funct' required. Please install 'r.width.funct' first
          using 'g.extension r.width.funct'
 ERROR: An ERROR occurred running r.basin
 SECTION 1 beginning: Initiating Variables. 4 sections total.
 > ...
 }}}

 `r.basin` is using function `error()` which is something different than
 function `fatal()`. `error()` just prints the message and continues,
 `fatal()` actually exits and raises. So, the behavior is correct according
 to implementation and is the same before r62566 and after r62705.

  * source:grass-addons/grass7/raster/r.basin/r.basin.py?rev=62705#L80
  * source:grass/trunk/lib/python/script/core.py?rev=62705#L569

 r62705 is doing two things. It adds a possibility to select method of
 error handling and unifies the implementation (see previous comments for
 discussion). Additionally it solves the issue with `g.message` which
 returns non-zero return code when an error is printed:

 {{{
 GRASS > g.message "Hello!"
 Hello!
 GRASS > echo $?
 0
 GRASS > g.message -w "Hello!"
 WARNING: Hello!
 GRASS > echo $?
 0
 GRASS > g.message -e "Hello!"
 ERROR: Hello!
 GRASS > echo $?
 1
 }}}

 I suppose that `g.message` behavior is advantageous for terminations of
 shell scripts using `set -e`. This makes `g.message` special comparing to
 other GRASS modules (alongside with `g.findfile`). You may find something
 like this in one of the earlier patches in this ticket, I forgot about it
 this time.

 Note also that the changes in error handling were applied to trunk only.
 The changes for addons are basically done but not committed because addons
 are supposed to be compatible with release branch. Also the changes will
 be done only for modules which are doing the correct error handling. The
 code ignoring errors will not be changed. Introduction of raise will show
 these ignored errors and will prevent further execution of the
 module/script since the the error occurred.

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2326#comment:34>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list