Select to view content in your preferred language

Scripting tool does not return line error consitent with the error line in the script

2093
10
02-28-2023 12:28 PM
JoeLummi
Occasional Contributor

I am porting a scripting tool to Pro v3.  The error messages returned by my scripting tool return a line where the code failed but this line number is not the same as the line number in my Python IDE where I am writing the code.

 

Here is the error message returned from the ArcToolbox scripting tool:

Capture.JPG

 

Here is where the code failed (although I have the code sorted out now).

Capture2.JPG

My question is why is the scripting tool error message not returning the same line as the Python code? How is it possible to debug scripts in Pro if you cannot determine the correct line of code that is failing?

Tags (4)
0 Kudos
10 Replies
DanPatterson
MVP Esteemed Contributor

hard to say, but what is in the vicinity of line 82 and what are the 8 messages that were reported? (eg did it report your line 96 and 97?  Also, how many lines of comments/ blank lines do you have (they may be stripped by the tool  when it makes the temporary script)


... sort of retired...
0 Kudos
JoeLummi
Occasional Contributor

Dan,

Other messages?  I have arcpy.AddMessage sprinkled around in my script to  provide feedback.  Blank lines not counting?  That is just wrong if that is the case.  Hopefully someone from the ESRI team can confirm that.

0 Kudos
JoeLummi
Occasional Contributor

Wouldn't appear to be blank lines issue based on this test that returned the correct line 4 has not attribute fubar.

 

 

try:
import arcpy

arcpy.fubar()

except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages(2)
# Return tool error messages for use with a script tool
arcpy.AddError(msgs)
# Print tool error messages for use in Python
print(msgs)
except:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
# Return Python error messages for use in script tool or Python window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# Print Python error messages for use in Python / Python window
print(pymsg)
print(msgs)

0 Kudos
JoeLummi
Occasional Contributor

I guess others have discovered the same issues with the Pro 3.x ATBX file as well.  See this parallel posts replies over at GIS Stack Exchange:  https://gis.stackexchange.com/questions/453100/arcpy-error-message-returns-absurd-line-error?noredir...

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Would you be able to report a bug to us for this? That'll help us keep track of it and notify affected customers once the issue is addressed. I agree its pretty annoying to not have the frames line up with the stated line numbers.

 

0 Kudos
JoeLummi
Occasional Contributor

Bug report?  Gosh, no, probably not.  That feel like working for free;)

 

ShaunWalbridge
Esri Regular Contributor

I understand your position. Generally, users providing enough context that we can reproduce the issue in house and logging issues allow all users to see when an issue is addressed makes the overall experience better, since there is a formal feedback loop. In some cases, bugs can only be addressed with the specific data provided by a user, and when choosing between issues, we will tend to choose ones that are reproducible and interpretable. In this case, we could address the issue in house without any further work and have fixed it for Pro 3.2.

Cheers, Shaun

DavidRichey_EWEB
New Contributor

More than annoying, it might end up wasting hours of ones time and make one question reality. I finally ended up on this thread after a commented out line came up as the source of the error.

0 Kudos
ShaunWalbridge
Esri Regular Contributor

This issue is addressed for toolboxes in Pro 3.2, if you're on 3.2 and seeing this behavior, please provide details on it.