Esri / data-assistant

ArcGIS Pro Add-in that assists in emergency management, local government and state government data aggregation workflows.
Apache License 2.0
22 stars 8 forks source link

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

Open MikeMillerGIS opened 7 years ago

MikeMillerGIS commented 7 years ago

@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.

JRosenfeldIntern commented 7 years ago

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.

MikeMillerGIS commented 7 years ago

Looks good.

JRosenfeldIntern commented 7 years ago

@MikeMillerGIS this was merged, issue can be closed.