Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 13, 2025

Summary

This PR enhances error diagnostics in bundle extraction to provide actionable information when I/O failures occur during file extraction. Previously, the code only checked if the extracted size didn't match the expected size and emitted generic error messages. Now, it provides detailed diagnostics to help troubleshoot disk full, quota exceeded, permission denied, or hardware errors.

Changes

Enhanced error handling in src/native/corehost/bundle/extractor.cpp:

  1. Added errno checking: Included <cerrno> to enable system error code inspection

  2. Enhanced fwrite error handling for both compressed and non-compressed extraction paths:

    • Always report errno and strerror(errno) when fwrite fails
    • Report expected vs actual byte counts for write failures
    • Ensures file is closed before throwing exception

Example Error Messages

Before

Failure extracting contents of the application bundle. Expected size:1048576 Actual size:524288
I/O failure when writing extracted files.

After - Disk Full

Failure extracting contents of the application bundle. Expected size:1048576 Actual size:524288
I/O failure when writing extracted files. errno: 28, No space left on device

After - Permission Denied

Failure extracting contents of the application bundle. Expected size:1048576 Actual size:0
I/O failure when writing extracted files. errno: 13, Permission denied

After - Compressed File Write Failure

I/O failure when writing decompressed file.
Expected: 4096 bytes, Written: 2048 bytes, errno: 28, No space left on device

Benefits

  • Actionable diagnostics: Provides specific error codes (ENOSPC, EDQUOT, EACCES, EIO) that indicate the root cause
  • Better supportability: Users and support teams can quickly identify whether the issue is disk space, permissions, quotas, or hardware
  • Simpler implementation: Direct errno reporting without conditional checks

Testing

  • ✅ Built successfully: ./build.sh clr+libs+host -rc release
  • ✅ All host tests passed: ./build.sh host.tests -rc release -test
    • AppHost.Bundle.Tests
    • HostActivation.Tests
    • Microsoft.NET.HostModel.Tests

Fixes #

Original prompt

Enhance error diagnostics in bundle extraction when fwrite fails in src/native/corehost/bundle/extractor.cpp. Currently, the code only checks if extracted_size != cast_size and emits a generic error. Instead, we should:

  • Check ferror(file) and report errno and strerror(errno) for specific I/O errors.
  • Report short writes distinctly from I/O errors.
  • Check fclose(file) for flush errors and report errno and strerror(errno) if it fails.
  • Emit more detailed trace output to help diagnose disk full, quota, permission, or hardware errors.

This change will improve supportability and troubleshooting for bundle extraction failures by providing actionable error diagnostics.

This pull request was created as a result of the following prompt from Copilot chat.

Enhance error diagnostics in bundle extraction when fwrite fails in src/native/corehost/bundle/extractor.cpp. Currently, the code only checks if extracted_size != cast_size and emits a generic error. Instead, we should:

  • Check ferror(file) and report errno and strerror(errno) for specific I/O errors.
  • Report short writes distinctly from I/O errors.
  • Check fclose(file) for flush errors and report errno and strerror(errno) if it fails.
  • Emit more detailed trace output to help diagnose disk full, quota, permission, or hardware errors.

This change will improve supportability and troubleshooting for bundle extraction failures by providing actionable error diagnostics.


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

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 13, 2025
@Copilot Copilot AI changed the title [WIP] Enhance error diagnostics in bundle extraction Enhance error diagnostics in bundle extraction when fwrite or fclose fails Oct 13, 2025
@Copilot Copilot AI requested a review from agocke October 13, 2025 23:00
Copilot finished work on behalf of agocke October 13, 2025 23:00
{
CompressionNative_InflateEnd(&zStream);
trace::error(_X("I/O failure when writing decompressed file."));
if (ferror(file))
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like ferror sets errno. But it looks like fwrite almost always does. Let's just print errno in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to always print errno without checking ferror. Commit: 5b4f0d2

{
trace::error(_X("Failure extracting contents of the application bundle. Expected size:%" PRId64 " Actual size:%zu"), size, extracted_size);
trace::error(_X("I/O failure when writing extracted files."));
if (ferror(file))
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to always print errno without checking ferror. Commit: 5b4f0d2

}

fclose(file);
if (fclose(file) != 0)
Copy link
Member

Choose a reason for hiding this comment

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

Let's ignore fclose failures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed fclose error checking. Commit: 5b4f0d2

@agocke
Copy link
Member

agocke commented Oct 14, 2025

@copilot please address comments

@Copilot Copilot AI changed the title Enhance error diagnostics in bundle extraction when fwrite or fclose fails Enhance error diagnostics in bundle extraction when fwrite fails Oct 14, 2025
Copilot finished work on behalf of agocke October 14, 2025 03:43
@Copilot Copilot AI requested a review from agocke October 14, 2025 03:43
@agocke
Copy link
Member

agocke commented Oct 14, 2025

Closing as I don't think there's a reliable way to view this error code for all platforms. Can't find a guarantee that errno is set

@agocke agocke closed this Oct 14, 2025
@agocke agocke deleted the copilot/enhance-error-diagnostics-bundle branch October 14, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants