From 6b7c6be5f595fbf71631d5974190a8b5b7ea6523 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 28 Oct 2025 10:02:58 +0000
Subject: [PATCH 1/4] Initial plan
From 46672eb58379ce3a4f395a02c4b63628f1b012ba Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 28 Oct 2025 10:15:40 +0000
Subject: [PATCH 2/4] Update exceptions to inherit from SharpCompressException
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
---
src/SharpCompress/Compressors/LZMA/ICoder.cs | 5 +-
.../Xz/XZIndexMarkerReachedException.cs | 4 +-
.../ExceptionHierarchyTests.cs | 118 ++++++++++++++++++
3 files changed, 123 insertions(+), 4 deletions(-)
create mode 100644 tests/SharpCompress.Test/ExceptionHierarchyTests.cs
diff --git a/src/SharpCompress/Compressors/LZMA/ICoder.cs b/src/SharpCompress/Compressors/LZMA/ICoder.cs
index 95134979..22648533 100644
--- a/src/SharpCompress/Compressors/LZMA/ICoder.cs
+++ b/src/SharpCompress/Compressors/LZMA/ICoder.cs
@@ -1,12 +1,13 @@
using System;
using System.IO;
+using SharpCompress.Common;
namespace SharpCompress.Compressors.LZMA;
///
/// The exception that is thrown when an error in input stream occurs during decoding.
///
-internal class DataErrorException : Exception
+internal class DataErrorException : SharpCompressException
{
public DataErrorException()
: base("Data Error") { }
@@ -15,7 +16,7 @@ internal class DataErrorException : Exception
///
/// The exception that is thrown when the value of an argument is outside the allowable range.
///
-internal class InvalidParamException : Exception
+internal class InvalidParamException : SharpCompressException
{
public InvalidParamException()
: base("Invalid Parameter") { }
diff --git a/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs b/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs
index bb006a35..f7fe0428 100644
--- a/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs
+++ b/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs
@@ -1,5 +1,5 @@
-using System;
+using SharpCompress.Common;
namespace SharpCompress.Compressors.Xz;
-public class XZIndexMarkerReachedException : Exception { }
+public class XZIndexMarkerReachedException : SharpCompressException { }
diff --git a/tests/SharpCompress.Test/ExceptionHierarchyTests.cs b/tests/SharpCompress.Test/ExceptionHierarchyTests.cs
new file mode 100644
index 00000000..64af90ed
--- /dev/null
+++ b/tests/SharpCompress.Test/ExceptionHierarchyTests.cs
@@ -0,0 +1,118 @@
+using System;
+using SharpCompress.Common;
+using SharpCompress.Compressors.Deflate;
+using SharpCompress.Compressors.LZMA;
+using SharpCompress.Compressors.Xz;
+using Xunit;
+
+namespace SharpCompress.Test;
+
+public class ExceptionHierarchyTests
+{
+ [Fact]
+ public void AllSharpCompressExceptions_InheritFromSharpCompressException()
+ {
+ // Verify that ArchiveException inherits from SharpCompressException
+ Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ArchiveException)));
+
+ // Verify that ExtractionException inherits from SharpCompressException
+ Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ExtractionException)));
+
+ // Verify that InvalidFormatException inherits from SharpCompressException (through ExtractionException)
+ Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(InvalidFormatException)));
+
+ // Verify that CryptographicException inherits from SharpCompressException
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(typeof(CryptographicException))
+ );
+
+ // Verify that IncompleteArchiveException inherits from SharpCompressException (through ArchiveException)
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(typeof(IncompleteArchiveException))
+ );
+
+ // Verify that ReaderCancelledException inherits from SharpCompressException
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(typeof(ReaderCancelledException))
+ );
+
+ // Verify that MultipartStreamRequiredException inherits from SharpCompressException (through ExtractionException)
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(
+ typeof(MultipartStreamRequiredException)
+ )
+ );
+
+ // Verify that MultiVolumeExtractionException inherits from SharpCompressException (through ExtractionException)
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(
+ typeof(MultiVolumeExtractionException)
+ )
+ );
+
+ // Verify that ZlibException inherits from SharpCompressException
+ Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ZlibException)));
+
+ // Verify that XZIndexMarkerReachedException inherits from SharpCompressException
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(
+ typeof(XZIndexMarkerReachedException)
+ )
+ );
+ }
+
+ [Fact]
+ public void SharpCompressException_CanBeCaughtByBaseType()
+ {
+ // Test that a derived exception can be caught as SharpCompressException
+ var exception = new InvalidFormatException("Test message");
+ var caughtException = false;
+
+ try
+ {
+ throw exception;
+ }
+ catch (SharpCompressException ex)
+ {
+ caughtException = true;
+ Assert.Same(exception, ex);
+ }
+
+ Assert.True(caughtException, "Exception should have been caught as SharpCompressException");
+ }
+
+ [Fact]
+ public void InternalLzmaExceptions_InheritFromSharpCompressException()
+ {
+ // Use reflection to verify internal exception types
+ var dataErrorExceptionType = Type.GetType(
+ "SharpCompress.Compressors.LZMA.DataErrorException, SharpCompress"
+ );
+ Assert.NotNull(dataErrorExceptionType);
+ Assert.True(typeof(SharpCompressException).IsAssignableFrom(dataErrorExceptionType));
+
+ var invalidParamExceptionType = Type.GetType(
+ "SharpCompress.Compressors.LZMA.InvalidParamException, SharpCompress"
+ );
+ Assert.NotNull(invalidParamExceptionType);
+ Assert.True(typeof(SharpCompressException).IsAssignableFrom(invalidParamExceptionType));
+ }
+
+ [Fact]
+ public void ExceptionConstructors_WorkCorrectly()
+ {
+ // Test parameterless constructor
+ var ex1 = new SharpCompressException();
+ Assert.NotNull(ex1);
+
+ // Test message constructor
+ var ex2 = new SharpCompressException("Test message");
+ Assert.Equal("Test message", ex2.Message);
+
+ // Test message and inner exception constructor
+ var inner = new InvalidOperationException("Inner");
+ var ex3 = new SharpCompressException("Test message", inner);
+ Assert.Equal("Test message", ex3.Message);
+ Assert.Same(inner, ex3.InnerException);
+ }
+}
From 2f27f1e6f988423d6fdb00bde3c415ce3a6b3a08 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 28 Oct 2025 10:18:42 +0000
Subject: [PATCH 3/4] Complete exception hierarchy implementation
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
---
src/SharpCompress/packages.lock.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/SharpCompress/packages.lock.json b/src/SharpCompress/packages.lock.json
index b85a38f7..904860ce 100644
--- a/src/SharpCompress/packages.lock.json
+++ b/src/SharpCompress/packages.lock.json
@@ -335,9 +335,9 @@
"net8.0": {
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
- "requested": "[8.0.20, )",
- "resolved": "8.0.20",
- "contentHash": "Rhcto2AjGvTO62+/VTmBpumBOmqIGp7nYEbTbmEXkCq4yPGxV8whju3/HsIA/bKyo2+DggaYk5+/8sxb1AbPTw=="
+ "requested": "[8.0.0, )",
+ "resolved": "8.0.0",
+ "contentHash": "B3etT5XQ2nlWkZGO2m/ytDYrOmSsQG1XNBaM6ZYlX5Ch/tDrMFadr0/mK6gjZwaQc55g+5+WZMw4Cz3m8VEF7g=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
From 210978ec2d0ec0077183f0b530dc52878a0e290c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 28 Oct 2025 11:13:51 +0000
Subject: [PATCH 4/4] Format code with CSharpier
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
---
src/SharpCompress/packages.lock.json | 6 +++---
tests/SharpCompress.Test/ExceptionHierarchyTests.cs | 12 +++++-------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/SharpCompress/packages.lock.json b/src/SharpCompress/packages.lock.json
index 904860ce..b85a38f7 100644
--- a/src/SharpCompress/packages.lock.json
+++ b/src/SharpCompress/packages.lock.json
@@ -335,9 +335,9 @@
"net8.0": {
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
- "requested": "[8.0.0, )",
- "resolved": "8.0.0",
- "contentHash": "B3etT5XQ2nlWkZGO2m/ytDYrOmSsQG1XNBaM6ZYlX5Ch/tDrMFadr0/mK6gjZwaQc55g+5+WZMw4Cz3m8VEF7g=="
+ "requested": "[8.0.20, )",
+ "resolved": "8.0.20",
+ "contentHash": "Rhcto2AjGvTO62+/VTmBpumBOmqIGp7nYEbTbmEXkCq4yPGxV8whju3/HsIA/bKyo2+DggaYk5+/8sxb1AbPTw=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
diff --git a/tests/SharpCompress.Test/ExceptionHierarchyTests.cs b/tests/SharpCompress.Test/ExceptionHierarchyTests.cs
index 64af90ed..b543d179 100644
--- a/tests/SharpCompress.Test/ExceptionHierarchyTests.cs
+++ b/tests/SharpCompress.Test/ExceptionHierarchyTests.cs
@@ -19,7 +19,9 @@ public class ExceptionHierarchyTests
Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ExtractionException)));
// Verify that InvalidFormatException inherits from SharpCompressException (through ExtractionException)
- Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(InvalidFormatException)));
+ Assert.True(
+ typeof(SharpCompressException).IsAssignableFrom(typeof(InvalidFormatException))
+ );
// Verify that CryptographicException inherits from SharpCompressException
Assert.True(
@@ -45,9 +47,7 @@ public class ExceptionHierarchyTests
// Verify that MultiVolumeExtractionException inherits from SharpCompressException (through ExtractionException)
Assert.True(
- typeof(SharpCompressException).IsAssignableFrom(
- typeof(MultiVolumeExtractionException)
- )
+ typeof(SharpCompressException).IsAssignableFrom(typeof(MultiVolumeExtractionException))
);
// Verify that ZlibException inherits from SharpCompressException
@@ -55,9 +55,7 @@ public class ExceptionHierarchyTests
// Verify that XZIndexMarkerReachedException inherits from SharpCompressException
Assert.True(
- typeof(SharpCompressException).IsAssignableFrom(
- typeof(XZIndexMarkerReachedException)
- )
+ typeof(SharpCompressException).IsAssignableFrom(typeof(XZIndexMarkerReachedException))
);
}