Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#2410 closed defect (fixed)

Python ScriptError

Reported by: martinl Owned by: grass-dev@…
Priority: normal Milestone: 7.2.0
Component: Python Version: svn-trunk
Keywords: ScriptError Cc: zarch
CPU: Unspecified Platform: Unspecified

Description

In trunk Python Scripting Library is used ScriptError from PyGRASS source:grass/trunk/lib/python/script/core.py#L36. It was introduced in r61187 by zarch. In relbr70 is still used it's own implementation of ScriptError source:grass/branches/releasebranch_7_0/lib/python/script/core.py#L70 which defines attribute value. This attribute is accessed on many places of Python Scripting Library or wxGUI, eg.

            except ScriptError as e:
                self.errorMsg = e.value

Since ScriptError from PyGRASS doesn't have this attribute, it fails with

  File "/opt/src/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/task.py", line 70, in __init__
    self.errorMsg = e.value
AttributeError: 'ScriptError' object has no attribute 'value'

Change History (4)

in reply to:  description ; comment:1 by zarch, 10 years ago

Replying to martinl:

In trunk Python Scripting Library is used ScriptError from PyGRASS source:grass/trunk/lib/python/script/core.py#L36. It was introduced in r61187 by zarch. In relbr70 is still used it's own implementation of ScriptError source:grass/branches/releasebranch_7_0/lib/python/script/core.py#L70 which defines attribute value. This attribute is accessed on many places of Python Scripting Library or wxGUI, eg.

            except ScriptError as e:
                self.errorMsg = e.value

Since ScriptError from PyGRASS doesn't have this attribute, it fails with

  File "/opt/src/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/task.py", line 70, in __init__
    self.errorMsg = e.value
AttributeError: 'ScriptError' object has no attribute 'value'

Right I did this change, we can modify ScriptError back to:

class ScriptError(Exception):
    def __init__(self, msg):
        self.value = msg

    def __str__(self):
        return self.value

# --- or alternatively
class ScriptError(Exception):
    @property
    def value(self):
        return self.args[0]

or change the e.value to e.args[0]

The value property seems to be used in:

$ grep --color=auto --exclude-dir={.svn,.git,.OBJ,locale,dist.x86_64-unknown-linux-gnu} -IrnE "\se\.value"
lib/python/script/task.py:70:                self.errorMsg = e.value
gui/wxpython/vnet/vnet_utils.py:80:        e = e.value
gui/wxpython/vnet/vnet_utils.py:119:        e = e.value
gui/wxpython/psmap/instructions.py:1546:            GError(message = e.value)
gui/wxpython/psmap/instructions.py:1584:                    GError(message = e.value)
gui/wxpython/psmap/instructions.py:1717:            GError(message = e.value)
gui/wxpython/mapwin/buffered.py:821:            GError(message = e.value)
gui/wxpython/location_wizard/wizard.py:2140:            return e.value
gui/wxpython/core/settings.py:48:            print >> sys.stderr, e.value
gui/wxpython/nviz/mapwindow.py:1355:                       message = e.value)
gui/wxpython/nviz/mapwindow.py:1397:                       message = e.value)
gui/wxpython/dbmgr/base.py:93:                   message = e.value)
gui/wxpython/dbmgr/base.py:1814:                       message = _("Loading attribute data failed.\n\n%s") % e.value)
gui/wxpython/dbmgr/base.py:1839:                           message = _("Loading attribute data failed.\n\n%s") % e.value)
gui/wxpython/wxplot/histogram.py:189:                   message = e.value)
gui/wxpython/wxplot/scatter.py:195:                   message = e.value)

Personally I think that we should change the ScriptError class definition.

in reply to:  1 comment:2 by martinl, 10 years ago

Replying to zarch:

Personally I think that we should change the ScriptError class definition.

for record - has been fixed in r61959.

comment:3 by martinl, 10 years ago

Resolution: fixed
Status: newclosed

comment:4 by neteler, 9 years ago

Milestone: 7.1.07.2.0

Milestone renamed

Note: See TracTickets for help on using tickets.