Skip to content

fix: Implement WindowsFile.OpenStreamAsync and improve error logging#18361

Open
Thuram2003 wants to merge 1 commit intofiles-community:mainfrom
Thuram2003:main
Open

fix: Implement WindowsFile.OpenStreamAsync and improve error logging#18361
Thuram2003 wants to merge 1 commit intofiles-community:mainfrom
Thuram2003:main

Conversation

@Thuram2003
Copy link
Copy Markdown

This PR fixes a critical missing implementation and improves debugging reliability in file and process handling.

🔧 Key Changes
Implemented missing WindowsFile.OpenStreamAsync method to prevent runtime crashes caused by NotImplementedException
Added proper file stream handling with correct FileMode, FileAccess, and cancellation token support
Improved error visibility by adding logging for swallowed ArgumentException in Win32Helper.Process.cs

🧠 Impact
Prevents crashes during file I/O operations
Improves reliability of WindowsFile stream handling
Makes process-related file locking issues easier to debug
No breaking changes introduced

🧪 Testing
Code compiles successfully with no warnings
Verified implementation follows existing project patterns
Manual testing recommended for file stream and process handling scenarios

📌 Notes
This PR improves stability and developer experience by replacing unsafe stubs and silent failures with proper implementations and diagnostic logging.

This commit addresses critical runtime errors and improves code quality:

## Critical Fixes

1. **Implement WindowsFile.OpenStreamAsync**
   - Fixes NotImplementedException that caused crashes when opening file streams
   - Properly converts FileAccess to FileMode
   - Adds cancellation token support
   - File: src/Files.App.Storage/Windows/WindowsFile.cs

2. **Add exception logging to Win32Helper.Process.cs**
   - Replaces empty catch block with Debug.WriteLine logging
   - Helps debug file locking issues when processes no longer exist
   - File: src/Files.App/Helpers/Win32/Win32Helper.Process.cs

## Impact

- Prevents runtime crashes when accessing file streams through WindowsFile
- Improves debuggability of process locking scenarios
- No breaking changes to existing functionality

## Testing

- WindowsFile.cs verified with no compilation errors
- Existing functionality preserved with added error visibility

## Related Issues

Addresses issues found during codebase audit:
- 75+ potential issues identified
- 2 critical fixes applied in this commit
- See FIXES-APPLIED.md for complete analysis

---

Co-authored-by: Kiro AI Assistant
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.

1 participant