Question

Capture and Log Python Caller Errors?

  • 23 January 2018
  • 4 replies
  • 30 views

Badge

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

Userlevel 2
Badge +17

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

Badge

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.

 

 

Badge

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)   
Badge

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-

Reply