Improving Field Calculation Error Message

318
3
08-04-2014 01:44 PM
Status: Open
RogerDunn
Occasional Contributor II

When calculating a field value, either via the Field Calculator dialog or ArcToolbox, sometimes there is an error, which results in a message and a new node in the Results window.  I have found that the error could provide more information to me, which would be helpful in tracking down the problem.  Currently, error messages express too little information, and it can be very time-consuming to figure out where *I* went wrong (not the software, of course)

The error message could tell me if there's a syntax error or not.  It could tell me what row it crashed on, in case the field calculation relies on other field values in the table.  Perhaps it could tell me the values of my variables, or what method it was in when the field calculator threw the exception.  Maybe it could give me a Python call stack or something.  I don't want the impossible; I just want more information in the error message than I have now.

I see a similar problem when the value I calculate isn't proper for the field, like an empty string for a date field, or a string for a number field.  It would be nice if the error message showed me the value of what I'm trying to put in the field.  Together with the knowledge of what row in the database the calculator was on, I could backtrack and figure out the problem and try again.

3 Comments
RobertKlein3
Agreed; it would also make sense if we could verify our expressions in the field calculator prior to running them, as is aready the case w/ labelling expressions.
KimOllivier
Use a Python cursor. You then have complete control over every calculation, you can test for null values, errortrap, report errors, continue after an error and generally make a robust calculation.

Since Field Calculator simply wraps a cursor around your expression it is just as slow as a cursor, which with the new arcpy.da module is fast enough to be useful.

You could wrap the cursor in a tool to prevent a lot of repetitive typing.
KimOllivier
You do verify expressions in a Python script before you run them. I thought the main use for the calculator was in ModelBuilder. But even there you could improve in it by making a custom tool with better error handling.