Skip to content

Detect YAML inputs by extension and report a missing file cleanly#161

Merged
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/125-yaml-detection
Jun 13, 2026
Merged

Detect YAML inputs by extension and report a missing file cleanly#161
maureeungaro merged 1 commit into
gemc:mainfrom
zhaozhiwen:fix/125-yaml-detection

Conversation

@zhaozhiwen

Copy link
Copy Markdown
Collaborator

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 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 message.

Validation: ran in the Geant4 11.4.1 dev container — gemc nonexistent.yaml now prints Cannot open yaml file ... Check the path and spelling. and exits cleanly (code 104) instead of terminating with an uncaught exception.

Fixes #125

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>
@maureeungaro maureeungaro merged commit 021367d into gemc:main Jun 13, 2026
30 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.

[Medium] YAML file detection uses substring match and misses YAML::BadFile, causing misparse and crashes

2 participants