Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 13, 2025

Summary

This PR enhances error handling in the extract() function of src/native/corehost/bundle/extractor.cpp to provide more detailed diagnostics when bundle extraction fails due to I/O errors.

Changes

Added Headers

  • <cerrno> - For errno constant definitions
  • <cstring> - For strerror() function to get human-readable error messages

Enhanced fwrite() Error Handling

Added ferror() checks and specific errno diagnostics in two write paths:

  1. Compressed write path (zlib decompression loop): When writing decompressed data fails
  2. Uncompressed write path: When the extracted size doesn't match the expected size

Both paths now check for and report specific error conditions:

  • ENOSPC - No space left on device
  • EDQUOT - Disk quota exceeded (with #ifdef guard for platform compatibility)
  • EIO - I/O error
  • EFBIG - File too large
  • Generic errno for other errors

Added fclose() Return Value Checking

Previously, fclose() was called without checking its return value. Now the code:

  • Checks if fclose() returns non-zero (indicating failure)
  • Provides detailed errno diagnostics for close failures
  • Throws an exception with specific error information

Benefits

This enhancement significantly improves diagnostics for bundle extraction failures by:

  1. Identifying root causes: Users and developers can now distinguish between disk full, quota exceeded, hardware errors, and other I/O issues
  2. Better error messages: Provides specific, actionable error information using strerror()
  3. Platform compatibility: Uses #ifdef EDQUOT guards since EDQUOT is not available on all platforms

Example Error Output

Before:

I/O failure when writing extracted files.

After:

I/O failure when writing extracted files.
No space left on device (ENOSPC). Error: No space left on device

This makes it much easier to diagnose and resolve bundle extraction issues in production environments.

Original prompt

Enhance error handling in the extract() function of src/native/corehost/bundle/extractor.cpp to check for specific fwrite failures using ferror() and errno. Include error checks for ENOSPC, EDQUOT, EIO, EFBIG, etc. Additionally, add error checking for fclose() return value. This will improve diagnostics during bundle extraction for both compressed and uncompressed write paths, and include necessary headers like errno.h and cstring.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Enhance error handling in extract function of extractor.cpp Enhance error handling in bundle extractor with ferror() and errno diagnostics Oct 13, 2025
@Copilot Copilot AI requested a review from agocke October 13, 2025 22:52
Copilot finished work on behalf of agocke October 13, 2025 22:52
@agocke agocke closed this Oct 14, 2025
@agocke agocke deleted the copilot/enhance-error-handling-extract-function branch October 14, 2025 01:02
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