[PR #990] [MERGED] Make all library exceptions inherit from SharpCompressException #1408

Open
opened 2026-01-29 22:20:25 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/990
Author: @Copilot
Created: 10/28/2025
Status: Merged
Merged: 10/28/2025
Merged by: @adamhathcock

Base: masterHead: copilot/add-common-exception-type


📝 Commits (4)

  • 6b7c6be Initial plan
  • 46672eb Update exceptions to inherit from SharpCompressException
  • 2f27f1e Complete exception hierarchy implementation
  • 210978e Format code with CSharpier

📊 Changes

3 files changed (+121 additions, -4 deletions)

View changed files

📝 src/SharpCompress/Compressors/LZMA/ICoder.cs (+3 -2)
📝 src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs (+2 -2)
tests/SharpCompress.Test/ExceptionHierarchyTests.cs (+116 -0)

📄 Description

  • Explore repository and understand current exception hierarchy
  • Build and test current state (526 tests pass)
  • Identify exceptions that need to be updated
  • Update DataErrorException to inherit from SharpCompressException
  • Update InvalidParamException to inherit from SharpCompressException
  • Update XZIndexMarkerReachedException to inherit from SharpCompressException
  • Add tests to verify new exception hierarchy
  • Build and test changes (530 tests pass)
  • Format code with CSharpier
  • Request code review (no issues found)
  • Run security checks (no vulnerabilities)

Summary:
Successfully implemented library-wise exception type hierarchy. All SharpCompress exceptions now inherit from SharpCompressException, allowing users to catch library-specific exceptions without masking unrelated errors.

Changes made:

  1. DataErrorException (LZMA) - now inherits from SharpCompressException
  2. InvalidParamException (LZMA) - now inherits from SharpCompressException
  3. XZIndexMarkerReachedException (XZ) - now inherits from SharpCompressException
  4. Added comprehensive test suite to verify exception hierarchy
  5. Applied CSharpier formatting to all code

Testing:

  • All 530 tests pass
  • Code review: No issues
  • Security scan: No vulnerabilities
Original prompt

This section details on the original issue you should resolve

<issue_title>Library-wise exception type</issue_title>
<issue_description>Please consider declaring a common exception type for the library (like SharpCompressException) and inheriting all specific exception types from it instead of subclassing base Exception class in different places.
It would improve user experience, as now users need to catch (Exception) which could mask actual errors such as hypothetical NullReferenceException in SharpCompress or exceptions thrown from some unrelated code residing in the same try block.</issue_description>

Comments on the Issue (you are @copilot in this section)

@adamhathcock Sounds good @adamhathcock Base exception: `SharpCompressException` from `ApplicationException`

Need to see what other exceptions I define as there seem to be some specific ones but mostly using framework ones</comment_new>
<comment_new>@adamhathcock
You're right. Not sure why I thought it was a good idea.

I also forgot the PR</comment_new>


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/990 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 10/28/2025 **Status:** ✅ Merged **Merged:** 10/28/2025 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `copilot/add-common-exception-type` --- ### 📝 Commits (4) - [`6b7c6be`](https://github.com/adamhathcock/sharpcompress/commit/6b7c6be5f595fbf71631d5974190a8b5b7ea6523) Initial plan - [`46672eb`](https://github.com/adamhathcock/sharpcompress/commit/46672eb58379ce3a4f395a02c4b63628f1b012ba) Update exceptions to inherit from SharpCompressException - [`2f27f1e`](https://github.com/adamhathcock/sharpcompress/commit/2f27f1e6f988423d6fdb00bde3c415ce3a6b3a08) Complete exception hierarchy implementation - [`210978e`](https://github.com/adamhathcock/sharpcompress/commit/210978ec2d0ec0077183f0b530dc52878a0e290c) Format code with CSharpier ### 📊 Changes **3 files changed** (+121 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Compressors/LZMA/ICoder.cs` (+3 -2) 📝 `src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs` (+2 -2) ➕ `tests/SharpCompress.Test/ExceptionHierarchyTests.cs` (+116 -0) </details> ### 📄 Description - [x] Explore repository and understand current exception hierarchy - [x] Build and test current state (526 tests pass) - [x] Identify exceptions that need to be updated - [x] Update DataErrorException to inherit from SharpCompressException - [x] Update InvalidParamException to inherit from SharpCompressException - [x] Update XZIndexMarkerReachedException to inherit from SharpCompressException - [x] Add tests to verify new exception hierarchy - [x] Build and test changes (530 tests pass) - [x] Format code with CSharpier - [x] Request code review (no issues found) - [x] Run security checks (no vulnerabilities) **Summary:** Successfully implemented library-wise exception type hierarchy. All SharpCompress exceptions now inherit from `SharpCompressException`, allowing users to catch library-specific exceptions without masking unrelated errors. **Changes made:** 1. `DataErrorException` (LZMA) - now inherits from `SharpCompressException` 2. `InvalidParamException` (LZMA) - now inherits from `SharpCompressException` 3. `XZIndexMarkerReachedException` (XZ) - now inherits from `SharpCompressException` 4. Added comprehensive test suite to verify exception hierarchy 5. Applied CSharpier formatting to all code **Testing:** - All 530 tests pass - Code review: No issues - Security scan: No vulnerabilities <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Library-wise exception type</issue_title> > <issue_description>Please consider declaring a common exception type for the library (like SharpCompressException) and inheriting all specific exception types from it instead of subclassing base Exception class in different places. > It would improve user experience, as now users need to `catch (Exception)` which could mask actual errors such as hypothetical NullReferenceException in SharpCompress or exceptions thrown from some unrelated code residing in the same try block.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > <comment_new><author>@adamhathcock</author><body> > Sounds good</body></comment_new> > <comment_new><author>@adamhathcock</author><body> > Base exception: > `SharpCompressException` from `ApplicationException` > > Need to see what other exceptions I define as there seem to be some specific ones but mostly using framework ones</body></comment_new> > <comment_new><author>@adamhathcock</author><body> > You're right. Not sure why I thought it was a good idea. > > I also forgot the PR</body></comment_new> > </comments> > </details> - Fixes adamhathcock/sharpcompress#830 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/adamhathcock/sharpcompress/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:20:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1408