Skip to content

avoid panic when opening FK files in convert-fk (propagate IO error)#687

Merged
ChristopherRabotin merged 1 commit intonyx-space:masterfrom
jmestwa-coder:convert-fk-file-open-panic
Apr 20, 2026
Merged

avoid panic when opening FK files in convert-fk (propagate IO error)#687
ChristopherRabotin merged 1 commit intonyx-space:masterfrom
jmestwa-coder:convert-fk-file-open-panic

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Summary

Fix a user-triggerable panic in the convert-fk CLI command when the input FK file is missing or cannot be opened.


Architectural Changes

None.


New Features

None.


Improvements

  • Ensures consistent error handling in convert-fk by propagating errors instead of panicking.
  • Aligns convert-fk behavior with existing CLI patterns (e.g., convert-tpc).

Bug Fixes

  • Fixes a panic caused by:

    • unwrap() in the CLI layer (main.rs)
    • panic! on file open failure in the parser (parse_file)
  • Missing or unreadable FK files now return a structured error instead of crashing the process.


Reproduction

cargo run -p anise-cli -- convert-fk ./missing_fk.txt ./out.epa

Before

  • Process panics due to unwrap() / panic!

After

  • Returns a handled CLI error (no panic)

Root Cause

  • The parser (parse_file) panicked when File::open failed.
  • The CLI (convert-fk) unconditionally unwrapped the result, propagating the panic to users.

Fix

  • Replace unwrap() in convert-fk with proper error propagation using .context(...) ?
  • Replace panic! on file open in the parser with DataSetError::IO

Testing and Validation

  • Added an integration test:

    • Verifies that a missing FK file no longer causes a panic
    • Confirms graceful error handling through the CLI
  • Manual validation:

    • Invalid input → returns error (no panic)
    • Valid input → unchanged behavior

Scope

  • Limited to the convert-fk path and its underlying parser behaviour
  • No refactoring or unrelated changes
  • No API or dependency changes

Impact

  • Prevents CLI crashes from invalid user input
  • Improves robustness and reliability of file handling
  • No behaviour change for valid inputs

Notes

  • This change specifically addresses the convert-fk path.
  • Similar patterns in other commands can be addressed separately if needed.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves error handling by replacing panics with proper error propagation when opening files and converting FK datasets. Specifically, it updates the anise-cli and the KPL parser to return Result types instead of using unwrap or panic!, and adds an integration test to verify that missing files are handled gracefully. I have no feedback to provide.

@ChristopherRabotin
Copy link
Copy Markdown
Member

Thanks for your contribution!

@ChristopherRabotin ChristopherRabotin merged commit a7403ed into nyx-space:master Apr 20, 2026
19 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.

2 participants