Skip to content

Raise Python exception on FoX XML parse errors (closes #724)#725

Merged
jameskermode merged 2 commits into
publicfrom
fix-fox-xml-error-propagation-724
May 12, 2026
Merged

Raise Python exception on FoX XML parse errors (closes #724)#725
jameskermode merged 2 commits into
publicfrom
fix-fox-xml-error-propagation-724

Conversation

@jameskermode
Copy link
Copy Markdown
Member

Summary

  • Register a FoX error handler in system_initialise (src/libAtoms/System.F90) that routes parse errors through system_abort. When running under quippy this triggers f90wrap_abort → Python RuntimeError, so try/except around Potential(param_filename=...) now actually works.
  • Bump src/fox submodule pointer to pick up the matching pluggable-handler hook (Add pluggable FoX_error_handler hook fox#4 — must merge first).
  • Build wiring: src/fox is now built before src/libAtoms, and libAtoms link_withs fox to expose FoX_set_error_handler.
  • New regression test tests/test_fox_xml_errors.py (subprocess-based, since the previous bug killed the interpreter).

Bug

Closes #724. Before this change, the reporter's reproducer silently exits with status 0 — try/except never runs:

ERROR(FoX)
Unexpected character found outside content (Possibly near line=0 col=2) ...

After:

caught exception: RuntimeError / FoX: Unexpected character found outside content ...

Root cause

FoX_error_base in the fox submodule called Fortran stop directly, bypassing libAtoms' system_abort + f90wrap_abort chain. libAtoms now installs a pluggable handler in fox (via libAtoms/fox#4) so the chain reaches Python.

Test plan

  • New tests/test_fox_xml_errors.py passes (runs the user's exact reproducer in a subprocess and asserts a caught exception).
  • Existing tests/test_symbol_resolution.py::test_error_handling_raises_exceptions (file-not-found case) still passes — verifies no regression in the existing error-propagation contract.
  • Full suite: Ran 51 tests in 10.898s — OK (skipped=6).
  • Standalone Fortran callers unchanged — system_abort still ends in stop 1 outside of quippy.

Dependency

🔴 libAtoms/fox#4 must merge first — this PR's submodule pointer references a commit that exists only on that fox PR's branch. CI will fail to fetch the submodule until that PR lands.

🤖 Generated with Claude Code

jameskermode and others added 2 commits May 11, 2026 15:50
Invalid XML in Potential(param_filename=...) currently silently exits
the Python interpreter because FoX_error_base calls Fortran stop
directly. This test runs the user's reproducer in a subprocess and
asserts a catchable exception is raised; in the current RED state the
subprocess exits 0 with no exception caught.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Install a FoX error handler in system_initialise that calls system_abort
instead of letting FoX issue a bare Fortran stop. When running under
quippy this triggers f90wrap_abort, so invalid XML in a param_filename
now raises a Python RuntimeError that can be caught with try/except,
instead of silently exiting the interpreter.

Build changes:
* src/fox is now built before src/libAtoms so the FoX module files are
  available when System.F90 is compiled.
* libAtoms links against fox to expose the new
  FoX_set_error_handler symbol.

The fox submodule pointer is bumped to pick up the matching
pluggable-handler commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jameskermode jameskermode force-pushed the fix-fox-xml-error-propagation-724 branch from 4a12731 to a803bdd Compare May 11, 2026 14:51
@jameskermode
Copy link
Copy Markdown
Member Author

@bernstei Do you want to take a look before I merge libAtoms/fox#4 and this? I have verified the test, but not manually checked much more than that. One-short Claude from your bug report and instruction to do test driven development was enough.

@bernstei
Copy link
Copy Markdown
Contributor

Looks reasonable to me. I'm happy with you merging, or could test the branch locally first if you prefer

@jameskermode
Copy link
Copy Markdown
Member Author

I've run it locally so no need. One the CI passes I will merge - I think that interim failure is unrelated, due to flaky DNS.

@jameskermode jameskermode merged commit 1e2f84b into public May 12, 2026
20 of 21 checks passed
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.

quippy fox xml reading errors exit without generating python exceptions

2 participants