Select to view content in your preferred language

Is there a way to only return the string in a raised error for a published geoprocessing service?

178
3
a month ago
Labels (1)
MBocek
by
New Contributor

I have a python geoprocessing toolbox that was published from Pro 2.9.5 to a 10.9.1 Enterprise server. I would like to display the error messages from the tool to a web UI, but I cannot find a way to only return the string in the raise error. For example, with the message level set to 'error', the tool always returns 5 messages

  • esriJobMessageTypeInformative: Submitted.
  • esriJobMessageTypeInformative: Executing...
  • esriJobMessageTypeError: Traceback (most recent call last): File "<string>", ***path removed ***  raise arcpy.ExecuteError('Shapefile is not a polygon. Input must be a polygon with a non empty feature.') arcgisscripting.ExecuteError: Shapefile is not a polygon. Input must be a polygon with a non empty feature.
  • esriJobMessageTypeError: Failed to execute (***tool name***).
  • esriJobMessageTypeError: Failed.

This is the code creating the error:

   if geom.type != 'polygon':
        raise arcpy.ExecuteError('Shapefile is not a polygon. Input must be a polygon with a non empty feature.')
 
I see an alternative would be to use arcpy.AddError, then exit() after. However, I still see an issue with additional error/informative messages being passed. Essentially, is there a way to only return the following?
 
  • esriJobMessageTypeError'Shapefile is not a polygon. Input must be a polygon with a non empty feature.'
3 Replies
DavidSolari
MVP Regular Contributor

How uncaught exceptions are handled is at the discretion of whatever's running Python, which in this case is the Web Tool infrastructure, so you're limited in how you can format your errors. A long shot might be the sys.tracebacklimit global, this SO post implies it might be able to cut down on what ArcGIS can report on.

0 Kudos
MBocek
by
New Contributor

Thank you for that traceback information! After testing, the arcpy. AddError('message') then exit() returns only the 'message' string as expected. However, there are always at least 5 messages returned if the job fails. 

  • esriJobMessageTypeInformative: Submitted.
  • esriJobMessageTypeInformative: Executing...
  • esriJobMessageTypeError: Shapefile is not a polygon. Input must be a polygon with a non empty feature.
  • esriJobMessageTypeError: Failed to execute (***tool name***).
  • esriJobMessageTypeError: Failed.

Is there any documentation that defines the number of esriJobMessageTypeInformative and orvesriJobMessageTypeError that will be returned from the server by default? I have the message level set to 'error', yet those first two informative entries always appear. Additionally, there are always two error messages at the end informing me the tool has failed. It would be great to have some ESRI documentation to send to the web team so they know the error message will be consistent. 

DavidSolari
MVP Regular Contributor

Those starting and ending messages are consistent with what appears in my environment. The message level appears to ignore those 2 leading messages and you always get 2 ending errors so I think you've hit the limit. Luckily the only internal info being leaked is the tool name so if you're able to instruct your users to ignore the other messages then you're good.

0 Kudos