Skip to content

expose ERROR arguments that can be used in conditional hook/cleanup u…#100

Open
colonesej wants to merge 4 commits into
developfrom
feature/signal_aware_error_function_and_exit_hook
Open

expose ERROR arguments that can be used in conditional hook/cleanup u…#100
colonesej wants to merge 4 commits into
developfrom
feature/signal_aware_error_function_and_exit_hook

Conversation

@colonesej

Copy link
Copy Markdown
Collaborator

Description

This pull request updates the error handling logic in the shell script generated by the preamble_error_function in pyflow/host.py. The main focus is to improve the way exit reasons, details, and return codes are captured and exported when errors or signals are trapped.

Improvements to error handling and signal trapping:

  • The ERROR handler now exports three variables: EXIT_REASON, EXIT_DETAIL, and EXIT_RC, providing more detailed context for errors and exits.
  • Signal traps now capture the return code (rc=$?) before invoking the ERROR handler, ensuring accurate reporting of the exit status when a signal is received.
  • The trap for exit (trap 0) is updated to pass the exit code to the ERROR handler, improving the accuracy of exit reporting.
  • This allows user custom exit_hook implementations that have conditional paths depending on task exit status. exit_hook is currently the only supported injection point for custom cleanup/post-execution logic

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the generated job shell preamble (via Host.preamble_error_function) to expose richer error/exit context to user-provided exit_hook logic by exporting EXIT_REASON, EXIT_DETAIL, and EXIT_RC, and by adjusting how traps invoke the ERROR handler.

Changes:

  • Export EXIT_REASON, EXIT_DETAIL, and EXIT_RC from the ERROR trap handler.
  • Update signal traps to capture $? before invoking ERROR.
  • Update the EXIT trap (trap 0) to pass exit status information into ERROR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyflow/host.py Outdated
Comment thread pyflow/host.py Outdated
Comment thread pyflow/host.py
@colonesej colonesej force-pushed the feature/signal_aware_error_function_and_exit_hook branch from d7b44c2 to 4e144e1 Compare July 2, 2026 15:12
@colonesej

Copy link
Copy Markdown
Collaborator Author

example usage: ecmwf/pyflow-wellies#65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants