data-assistant icon indicating copy to clipboard operation
data-assistant copied to clipboard

When Cursor fails any row, expose option to stop all Execution

Open MikeMillerGIS opened this issue 8 years ago • 3 comments

@gg7aph encountered this when he did not properly define all his domain maps. A string was attempted to be set into an int field. Execution should stop and inform the user of the error so they can correct the process.

MikeMillerGIS avatar Aug 07 '17 13:08 MikeMillerGIS

The current fix Paul and I quickly worked up for this changes some code in dlaFieldCalculator.py (the file that crashes on this error)

 try:
                # printRow(row,names)
                updateCursor.updateRow(row)
            except:
                error = traceback.format_exc()
                error_field = re.findall(r"\[(.+)\]", error)
                # Pulls the field name from the arcpy error message from updateCursor
                if error_field:
                    error_value = row[names.index(error_field[0])]
                    error = "{} Value: {}".format(error, error_value)
                dla.addError(error)
                if True:  
                    sys.exit(1)

This will quit after the first updateCursor row crash and prints out a message like this: image

Here the user can see which field caused the crash and what value was the culprit. In this way the user can quickly determine the cause and amend it without having to deal with incorrect appendages and unneeded digging.

The "if True:" here is for the potential that the user can choose whether or not they'd like the script to continue running on this first error or not.

JRosenfeldIntern avatar Aug 07 '17 20:08 JRosenfeldIntern

Looks good.

MikeMillerGIS avatar Aug 07 '17 22:08 MikeMillerGIS

@MikeMillerGIS this was merged, issue can be closed.

JRosenfeldIntern avatar Aug 16 '17 21:08 JRosenfeldIntern