[GRASS-dev] How to improve flags related error message in pygrass module?

Markus Neteler neteler at osgeo.org
Mon Jan 15 02:12:46 PST 2018


Hi devs,

when accidentially using a wrong flag, the resulting error message is
"unhelpful":

user at fry ~ $ python grass_scripts/grass_dem.py
GRASSBIN: grass74
GISBASE: /home/user/source/grass-7.4.svn/dist.x86_64-pc-linux-gnu
{u'MAPSET': u"'PERMANENT';", u'GISDBASE': u"'/home/user/grassdata';",
u'LOCATION_NAME': u"'nrw';"}
Traceback (most recent call last):
  File "grass_scripts/grass_dem.py", line 17, in <module>

r.in_gdal(input="/home/user/geodaten/ASTGTM2_N50E007_dem.tif",output="dem_nrw",flags="e",overwrite="OVR")
  File
"/home/user/source/grass-7.4.svn/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py",
line 647, in __call__
    self.check()
  File
"/home/user/source/grass-7.4.svn/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py",
line 705, in check
    if flg and flg.suppress_required:
TypeError: __nonzero__ should return bool or int, returned str

This script was written by a PyGRASS newcomer who reused code from the
Wiki. The reason for the error is
overwrite="OVR"

which is incorrect (must be: overwrite=True or =False).

The related code is around l705 in
lib/python/pygrass/modules/interface/module.py

    def check(self):
        """Check the correctness of the provide parameters"""
        required = True
        for flg in self.flags.values():
            if flg and flg.suppress_required:
                required = False

Could a python expert here please suggest how to generate a more
reasonable error message?

thanks
Markus


More information about the grass-dev mailing list