Skip to content

Commit

Permalink
Merge PR #369: Make the custom exception types serializable
Browse files Browse the repository at this point in the history
* Make all the custom exception classes serializable.
* Add unit tests for exception serialization.
  • Loading branch information
Numpsy authored and piksel committed Aug 8, 2019
1 parent ffe5115 commit 36ece7a
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2Exception.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib.BZip2
{
/// <summary>
/// BZip2Exception represents exceptions specific to BZip2 classes and code.
/// </summary>
[Serializable]
public class BZip2Exception : SharpZipBaseException
{
/// <summary>
Expand Down Expand Up @@ -32,5 +34,21 @@ public BZip2Exception(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the BZip2Exception class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected BZip2Exception(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib
{
Expand All @@ -8,6 +9,7 @@ namespace ICSharpCode.SharpZipLib
/// </summary>
/// <remarks>NOTE: Not all exceptions thrown will be derived from this class.
/// A variety of other exceptions are possible for example <see cref="ArgumentNullException"></see></remarks>
[Serializable]
public class SharpZipBaseException : Exception
{
/// <summary>
Expand Down Expand Up @@ -36,5 +38,21 @@ public SharpZipBaseException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the SharpZipBaseException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected SharpZipBaseException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib
{
/// <summary>
/// Indicates that an error occured during decoding of a input stream due to corrupt
/// data or (unintentional) library incompability.
/// </summary>
[Serializable]
public class StreamDecodingException : SharpZipBaseException
{
private const string GenericMessage = "Input stream could not be decoded";
Expand All @@ -28,5 +30,21 @@ public StreamDecodingException(string message) : base(message) { }
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public StreamDecodingException(string message, Exception innerException) : base(message, innerException) { }

/// <summary>
/// Initializes a new instance of the StreamDecodingException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected StreamDecodingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib
{
/// <summary>
/// Indicates that the input stream could not decoded due to known library incompability or missing features
/// </summary>
[Serializable]
public class StreamUnsupportedException : StreamDecodingException
{
private const string GenericMessage = "Input stream is in a unsupported format";
Expand All @@ -27,5 +29,21 @@ public StreamUnsupportedException(string message) : base(message) { }
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public StreamUnsupportedException(string message, Exception innerException) : base(message, innerException) { }

/// <summary>
/// Initializes a new instance of the StreamUnsupportedException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected StreamUnsupportedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib
{
/// <summary>
/// Indicates that the input stream could not decoded due to the stream ending before enough data had been provided
/// </summary>
[Serializable]
public class UnexpectedEndOfStreamException : StreamDecodingException
{
private const string GenericMessage = "Input stream ended unexpectedly";
Expand All @@ -27,5 +29,21 @@ public UnexpectedEndOfStreamException(string message) : base(message) { }
/// <param name="message">A message describing the exception.</param>
/// <param name="innerException">The inner exception</param>
public UnexpectedEndOfStreamException(string message, Exception innerException) : base(message, innerException) { }

/// <summary>
/// Initializes a new instance of the UnexpectedEndOfStreamException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected UnexpectedEndOfStreamException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib
{
/// <summary>
/// Indicates that a value was outside of the expected range when decoding an input stream
/// </summary>
[Serializable]
public class ValueOutOfRangeException : StreamDecodingException
{
/// <summary>
Expand Down Expand Up @@ -44,5 +46,21 @@ private ValueOutOfRangeException()
private ValueOutOfRangeException(string message, Exception innerException) : base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the ValueOutOfRangeException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected ValueOutOfRangeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
18 changes: 18 additions & 0 deletions src/ICSharpCode.SharpZipLib/Core/InvalidNameException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib.Core
{
/// <summary>
/// InvalidNameException is thrown for invalid names such as directory traversal paths and names with invalid characters
/// </summary>
[Serializable]
public class InvalidNameException : SharpZipBaseException
{
/// <summary>
Expand All @@ -31,5 +33,21 @@ public InvalidNameException(string message) : base(message)
public InvalidNameException(string message, Exception innerException) : base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the InvalidNameException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected InvalidNameException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
18 changes: 18 additions & 0 deletions src/ICSharpCode.SharpZipLib/GZip/GZipException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib.GZip
{
/// <summary>
/// GZipException represents exceptions specific to GZip classes and code.
/// </summary>
[Serializable]
public class GZipException : SharpZipBaseException
{
/// <summary>
Expand Down Expand Up @@ -32,5 +34,21 @@ public GZipException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the GZipException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected GZipException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
18 changes: 18 additions & 0 deletions src/ICSharpCode.SharpZipLib/Lzw/LzwException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib.Lzw
{
/// <summary>
/// LzwException represents exceptions specific to LZW classes and code.
/// </summary>
[Serializable]
public class LzwException : SharpZipBaseException
{
/// <summary>
Expand Down Expand Up @@ -32,5 +34,21 @@ public LzwException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the LzwException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected LzwException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
18 changes: 18 additions & 0 deletions src/ICSharpCode.SharpZipLib/Tar/TarException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib.Tar
{
/// <summary>
/// TarException represents exceptions specific to Tar classes and code.
/// </summary>
[Serializable]
public class TarException : SharpZipBaseException
{
/// <summary>
Expand Down Expand Up @@ -32,5 +34,21 @@ public TarException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the TarException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected TarException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
18 changes: 18 additions & 0 deletions src/ICSharpCode.SharpZipLib/Zip/ZipException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace ICSharpCode.SharpZipLib.Zip
{
/// <summary>
/// ZipException represents exceptions specific to Zip classes and code.
/// </summary>
[Serializable]
public class ZipException : SharpZipBaseException
{
/// <summary>
Expand Down Expand Up @@ -32,5 +34,21 @@ public ZipException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the ZipException class with serialized data.
/// </summary>
/// <param name="info">
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
/// object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
/// about the source or destination.
/// </param>
protected ZipException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Loading

0 comments on commit 36ece7a

Please sign in to comment.