Skip to content

Add pluggable FoX_error_handler hook#4

Merged
jameskermode merged 1 commit into
cmake-install-supportfrom
fix-fox-error-handler-quip-724
May 11, 2026
Merged

Add pluggable FoX_error_handler hook#4
jameskermode merged 1 commit into
cmake-install-supportfrom
fix-fox-error-handler-quip-724

Conversation

@jameskermode
Copy link
Copy Markdown
Member

Summary

  • Add an optional procedure-pointer hook in m_common_error (FoX_set_error_handler) that FoX_error_base consults before its historical stop.
  • Lets a host library (e.g. libAtoms) install its own terminator so XML parse errors can propagate as language-level exceptions instead of silently killing the process.
  • Historical stop path is preserved when no handler is registered.

Motivation

Needed to fix libAtoms/QUIP#724 — quippy's Potential(param_filename=...) silently exits the Python interpreter on malformed XML because FoX calls Fortran stop directly, bypassing libAtoms' system_abortf90wrap_abort path. With this hook, libAtoms registers a handler that routes through system_abort, so Python sees a catchable RuntimeError.

Companion QUIP PR will register the handler in system_initialise.

Test plan

  • Builds cleanly as part of QUIP's meson build.
  • QUIP unit tests pass (51/51, including new tests/test_fox_xml_errors.py and the existing test_error_handling_raises_exceptions).
  • Standalone Fortran callers unaffected — when no handler is registered, behaviour is identical (stop after stderr message).

🤖 Generated with Claude Code

FoX_error_base previously called stop directly, which prevented host
programs (notably quippy via libAtoms' system_abort + f90wrap_abort
chain) from converting XML parse errors into language-level exceptions.

Introduce an optional procedure-pointer hook so a host library can
install its own terminator. The historical stop path is preserved as
the fallback when no handler is registered.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant