Skip to main content
Question

Capture and Log Python Caller Errors?

  • January 23, 2018
  • 4 replies
  • 160 views

Forum|alt.badge.img

In my workbench, all "Not Merged" / "Rejected" paths etc, redirect to a FeatureWriter that logs errors to the database.

However, the PythonCaller only has the "Output" path - how would I capture and log these exceptions?

Could I do something like this?

  • Update PythonCaller to Catch the Exception and store detail in an Attribute (don't raise exception)

     

try:
	...
except:
	feature.setAttribute("Error", sys.exc_info()[0])
  • Use Tester to check if Error Message exists
  • Fork based on Error contents
  • Wire-up to exception-logging path

4 replies

takashi
Influencer
  • January 23, 2018

If you don't want the translation to stop when an exception is raised at runtime, you have to implement the script to detect the exception and output a specific feature which contains information on the error, and then filter out the feature with a subsequent transformer e.g. Tester, TestFilter etc.

Probably you want to vote up this Idea: Add Rejected-port to the PythonCaller


Forum|alt.badge.img
  • Author
  • January 23, 2018
takashi wrote:

If you don't want the translation to stop when an exception is raised at runtime, you have to implement the script to detect the exception and output a specific feature which contains information on the error, and then filter out the feature with a subsequent transformer e.g. Tester, TestFilter etc.

Probably you want to vote up this Idea: Add Rejected-port to the PythonCaller

Thanks Takashi, will do.

 

 


Forum|alt.badge.img
  • Author
  • January 23, 2018

Just for the benefit of others, the above process can be followed - I've also added additional information, such as the line number:

import sys
...
    try:
	...
    except Exception as e:
        error = 'Error on line ' + str(sys.exc_info()[-1].tb_lineno) + ' - ' + str(type(e).__name__) + ' - ' + str(e) 
        print error
        feature.setAttribute("_error", error)   

apence231
Contributor
Forum|alt.badge.img+7
  • Contributor
  • May 15, 2019
peterx wrote:

Just for the benefit of others, the above process can be followed - I've also added additional information, such as the line number:

import sys
...
    try:
	...
    except Exception as e:
        error = 'Error on line ' + str(sys.exc_info()[-1].tb_lineno) + ' - ' + str(type(e).__name__) + ' - ' + str(e) 
        print error
        feature.setAttribute("_error", error)   

This worked like a charm! Thanks for the bit of code-


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings