Can Analysis Automation Stop Python From Running Rest of Script When There Is an Error?

Updated Jun 20, 2023

Reported In

Software

  • DIAdem
  • Analysis Server

Programming Language

  • Python

Issue Details

I am running a Python script in an Analaysis Automation procedure, but would like for the script to stop running when there is an error. Is there a way to achieve this? 

Solution

There are several methods you can use to achieve this. Following are some of the options: 
  • Use RaiseError for ContextRun method to terminate the On_Run_AnalysisProcedure event with an error message without executing further commands. This will abort the script with an error message that includes the error number and text specified in the script. 
  • Use (external link) Python's syntax for raising exceptions to raise a ValueError. This will throw a ValueError exception with the error message text. 
  • Use LogError for ContextRun method to create an error and mark the file in the Analysis Server as "failed," and include (external link) Python's system-specific function , sys.exit([arg]), to terminate and exit out of Python. The LogError method itself only logs the error and does not stop the script.