Skip to content

Use more SharpCompress exceptions instead of generic ones#1224

Merged
adamhathcock merged 3 commits intomasterfrom
adam/conslidate-exceptions
Feb 17, 2026
Merged

Use more SharpCompress exceptions instead of generic ones#1224
adamhathcock merged 3 commits intomasterfrom
adam/conslidate-exceptions

Conversation

@adamhathcock
Copy link
Owner

This pull request standardizes exception handling throughout the archive reading and creation code, replacing general .NET exceptions with custom exceptions that are more descriptive and relevant to archive operations. This improves error clarity and consistency, making it easier to handle and debug archive-related issues.

Exception Handling Improvements:

  • Replaced usages of InvalidOperationException, InvalidDataException, EndOfStreamException, and FormatException with custom exceptions such as ArchiveOperationException, InvalidFormatException, and IncompleteArchiveException in archive factory and header processing code (ArchiveFactory.cs, ArchiveFactory.Async.cs, AceHeader.cs, AceHeader.Async.cs, AceMainHeader.cs, AceMainHeader.Async.cs, ArjHeader.cs, ArjHeader.Async.cs, ArjLocalHeader.cs, ArjMainHeader.cs, AsyncMarkingBinaryReader.cs, MarkHeader.Async.cs). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]

Code Consistency and Cleanup:

  • Updated calls to use Constants.DefaultCultureInfo without the global namespace prefix, simplifying and unifying code style in volume factory classes (ArchiveVolumeFactory.cs, RarArchiveVolumeFactory.cs, ZipArchiveVolumeFactory.cs). [1] [2] [3] [4] [5] [6]

@adamhathcock adamhathcock marked this pull request as ready for review February 16, 2026 16:40
Copilot AI review requested due to automatic review settings February 16, 2026 16:40
@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Feb 16, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (86 files)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes exception handling throughout SharpCompress by replacing generic .NET exceptions with custom SharpCompress exceptions. The primary improvement is the introduction of ArchiveOperationException to replace InvalidOperationException for archive-specific operation errors, along with consistent use of existing custom exceptions like IncompleteArchiveException and InvalidFormatException.

Changes:

  • Introduced new ArchiveOperationException class that inherits from SharpCompressException
  • Replaced ~100+ occurrences of InvalidOperationException with ArchiveOperationException
  • Replaced ~50+ occurrences of EndOfStreamException with IncompleteArchiveException
  • Replaced ~30+ occurrences of InvalidDataException, FormatException, and OverflowException with InvalidFormatException
  • Removed unnecessary global:: namespace qualifiers for Constants.DefaultCultureInfo throughout the codebase
  • Updated XML documentation comments to reflect new exception types

Reviewed changes

Copilot reviewed 115 out of 115 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/SharpCompress/Common/SharpCompressException.cs Defines new ArchiveOperationException class with standard constructors
tests/SharpCompress.Test/ExceptionHierarchyTests.cs Adds test coverage for ArchiveOperationException hierarchy
tests/SharpCompress.Test/Rar/RarReaderAsyncTests.cs Updates exception assertions (contains inconsistency)
tests/SharpCompress.Test/Xz/Filters/Lzma2Tests.cs Updates OverflowException → InvalidFormatException
tests/SharpCompress.Test/UtilityTests.cs Updates EndOfStreamException → IncompleteArchiveException
tests/SharpCompress.Test/Streams/* Updates InvalidOperationException → ArchiveOperationException for stream operations
tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs Updates exception types for multi-volume archive tests
tests/SharpCompress.Test/Rar/RarArchiveTests.cs Updates exception types for RAR validation tests
tests/SharpCompress.Test/BZip2/BZip2ReaderTests.cs Updates exception type for reader factory test
src/SharpCompress/Writers/Zip/ZipWriter.cs Replaces InvalidOperationException for missing compression providers
src/SharpCompress/Utility.cs Replaces EndOfStreamException → IncompleteArchiveException with descriptive message
src/SharpCompress/Utility.Async.cs Replaces EndOfStreamException → IncompleteArchiveException with descriptive message
src/SharpCompress/Readers/Zip/ZipReader.Async.cs Replaces InvalidOperationException for missing current entry
src/SharpCompress/Readers/Rar/RarReader*.cs Replaces InvalidOperationException for redirect entries
src/SharpCompress/Readers/AbstractReader.cs Replaces InvalidOperationException for sync/async mixing
src/SharpCompress/Providers/*.cs Replaces InvalidOperationException for context-required operations and missing providers
src/SharpCompress/IO/*.cs Replaces InvalidOperationException for stream operation errors
src/SharpCompress/Compressors/**/*.cs Replaces EndOfStreamException, InvalidDataException, and FormatException throughout all compressor implementations
src/SharpCompress/Common/**/*.cs Replaces InvalidOperationException and EndOfStreamException in common archive handling code
src/SharpCompress/Archives/*.cs Replaces InvalidOperationException in archive factories and volume handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@adamhathcock adamhathcock merged commit 0b68146 into master Feb 17, 2026
12 checks passed
@adamhathcock adamhathcock deleted the adam/conslidate-exceptions branch February 17, 2026 10:13
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