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
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
close_filemethod is idempotent - it returnsOk(())even when called on a non-existent handletest_double_close_file_errorintests/file_io_error_handling_test.rshas a misleading name and structure that suggests it expects an error, but only assertsresult.is_ok()Proposed Solutions
Choose one of the following approaches:
Option 1: Enforce Error on Double Close
async fn close_fileinsrc/interpreter/mod.rsto returnErrwhen handle_id is missingOption 2: Document and Test Idempotent Close (Recommended)
test_double_close_file_is_noopwhen error:branch from the testFiles Affected
tests/file_io_error_handling_test.rs(around line 190)src/interpreter/mod.rs(close_file implementation)Context
This issue was identified during code review of PR #150 which enhances file I/O capabilities.
Related:
Reporter: @logbie