Detect YAML inputs by extension and report a missing file cleanly#161
Merged
Conversation
Two defects in YAML handling: - findYamls classified any token *containing* ".yaml"/".yml" as an input file (substring match). An option value like -prefix=run.yaml.bak was misclassified, then skipped from option parsing (line 122) and silently dropped, and fed to YAML::LoadFile. Match a trailing extension instead. - setOptionsValuesFromYamlFile caught only YAML::ParserException. YAML::LoadFile throws YAML::BadFile (a sibling, both derive from YAML::Exception) for a missing/unreadable path, so a mistyped *.yaml filename escaped the catch and called std::terminate. Add a BadFile catch with a clean "cannot open" message. Verified: "gemc nonexistent.yaml" now prints "Cannot open yaml file ... Check the path and spelling." and exits cleanly instead of terminating with an uncaught exception (Geant4 11.4.1 dev container). Fixes gemc#125 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Two defects in YAML handling:
findYamlsclassified any token containing.yaml/.ymlas an input file (substring match). An option value like-prefix=run.yaml.bakwas misclassified, then skipped from option parsing and silently dropped, and fed toYAML::LoadFile. Match a trailing extension instead.setOptionsValuesFromYamlFilecaught onlyYAML::ParserException.YAML::LoadFilethrowsYAML::BadFile(a sibling; both derive fromYAML::Exception) for a missing/unreadable path, so a mistyped*.yamlfilename escaped the catch and calledstd::terminate. Add aBadFilecatch with a clean message.Validation: ran in the Geant4 11.4.1 dev container —
gemc nonexistent.yamlnow printsCannot open yaml file ... Check the path and spelling.and exits cleanly (code 104) instead of terminating with an uncaught exception.Fixes #125