Skip to content

Clarify and document double-close file handle behavior #152

Description

@coderabbitai

Issue Description

There is currently ambiguity in the expected behavior when closing a file handle twice in the WFL interpreter. The test suite and implementation have conflicting expectations that need to be resolved.

Current State

  • The interpreter's close_file method is idempotent - it returns Ok(()) even when called on a non-existent handle
  • The test test_double_close_file_error in tests/file_io_error_handling_test.rs has a misleading name and structure that suggests it expects an error, but only asserts result.is_ok()
  • This creates confusion about the intended behavior

Proposed Solutions

Choose one of the following approaches:

Option 1: Enforce Error on Double Close

  • Modify async fn close_file in src/interpreter/mod.rs to return Err when handle_id is missing
  • Update tests to expect and properly handle this error
  • Document that double-closing is an error condition

Option 2: Document and Test Idempotent Close (Recommended)

  • Rename test to test_double_close_file_is_noop
  • Remove the when error: branch from the test
  • Assert that the second close operation is harmless
  • Update comments to clearly state that closing an already-closed handle is safe and should not raise an error

Files Affected

  • tests/file_io_error_handling_test.rs (around line 190)
  • src/interpreter/mod.rs (close_file implementation)
  • Documentation/comments describing file I/O behavior

Context

This issue was identified during code review of PR #150 which enhances file I/O capabilities.

Related:

Reporter: @logbie

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions