Use more SharpCompress exceptions instead of generic ones#1224
Merged
adamhathcock merged 3 commits intomasterfrom Feb 17, 2026
Merged
Use more SharpCompress exceptions instead of generic ones#1224adamhathcock merged 3 commits intomasterfrom
adamhathcock merged 3 commits intomasterfrom
Conversation
Contributor
Contributor
There was a problem hiding this comment.
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
ArchiveOperationExceptionclass that inherits fromSharpCompressException - Replaced ~100+ occurrences of
InvalidOperationExceptionwithArchiveOperationException - Replaced ~50+ occurrences of
EndOfStreamExceptionwithIncompleteArchiveException - Replaced ~30+ occurrences of
InvalidDataException,FormatException, andOverflowExceptionwithInvalidFormatException - Removed unnecessary
global::namespace qualifiers forConstants.DefaultCultureInfothroughout 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.
This was referenced Mar 4, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
InvalidOperationException,InvalidDataException,EndOfStreamException, andFormatExceptionwith custom exceptions such asArchiveOperationException,InvalidFormatException, andIncompleteArchiveExceptionin 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:
Constants.DefaultCultureInfowithout 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]