fix: validate the topology before opening the output file - #181
Open
galjos wants to merge 1 commit into
Open
Conversation
TopologyFileWriter.write opened the output file before any of the bonded parameters were checked, and the per-section checks for a missing bond, angle, dihedral or improper type only ran from inside the write helpers. Opening the file in overwrite mode truncates it, so a topology with a missing type raised TopologyFileError only after the destination had already been emptied, silently destroying an existing topology file. The type checks now run against the sections that are about to be written before the file is opened, so a rejected topology leaves the destination untouched. Writing itself is wrapped in a try/finally so that the file handle is closed even when a later write fails.
Contributor
|
PYLINT REPORT Your code has been rated at 9.78/10 Full reportRaw metrics
Duplication
Messages by category
% errors / warnings by module
Messages
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #181 +/- ##
==========================================
+ Coverage 93.86% 93.94% +0.07%
==========================================
Files 177 177
Lines 9215 9231 +16
==========================================
+ Hits 8650 8672 +22
+ Misses 565 559 -6
🚀 New features to boost your workflow:
|
97gamjak
reviewed
Aug 23, 2026
| "bonds": "bond", | ||
| "angles": "angle", | ||
| "dihedrals": "dihedral", | ||
| "impropers": "improper", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Writing a topology that fails validation destroyed the existing file.
The writer opened the file, which truncates in overwrite mode, and only then validated, so the error left an empty file behind. The handle was also not closed on that path. Validation now runs before the file is opened, and the write loop closes the file in a finally block.
Present in v1.5.0. 949 tests pass in both type checking modes.