Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions src/Renci.SshNet/Common/NetConfServerException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
#if NETFRAMEWORK
using System.Runtime.Serialization;
#endif // NETFRAMEWORK
#nullable enable
using System;

namespace Renci.SshNet.Common
{
Expand All @@ -10,7 +8,7 @@ namespace Renci.SshNet.Common
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif // NETFRAMEWORK
#endif
public class NetConfServerException : SshException
{
/// <summary>
Expand All @@ -23,34 +21,27 @@ public NetConfServerException()
/// <summary>
/// Initializes a new instance of the <see cref="NetConfServerException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public NetConfServerException(string message)
/// <inheritdoc cref="Exception(string)" path="/param"/>
public NetConfServerException(string? message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="NetConfServerException"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public NetConfServerException(string message, Exception innerException)
/// <inheritdoc cref="Exception(string, Exception)" path="/param"/>
public NetConfServerException(string? message, Exception? innerException)
: base(message, innerException)
{
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="NetConfServerException"/> class.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
/// <exception cref="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (0). </exception>
protected NetConfServerException(SerializationInfo info, StreamingContext context)
/// <inheritdoc/>
protected NetConfServerException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif // NETFRAMEWORK
#endif
}
}
29 changes: 10 additions & 19 deletions src/Renci.SshNet/Common/ProxyException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
#if NETFRAMEWORK
using System.Runtime.Serialization;
#endif // NETFRAMEWORK
#nullable enable
using System;

namespace Renci.SshNet.Common
{
Expand All @@ -10,7 +8,7 @@ namespace Renci.SshNet.Common
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif // NETFRAMEWORK
#endif
public class ProxyException : SshException
{
/// <summary>
Expand All @@ -23,34 +21,27 @@ public ProxyException()
/// <summary>
/// Initializes a new instance of the <see cref="ProxyException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public ProxyException(string message)
/// <inheritdoc cref="Exception(string)" path="/param"/>
public ProxyException(string? message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ProxyException"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public ProxyException(string message, Exception innerException)
/// <inheritdoc cref="Exception(string, Exception)" path="/param"/>
public ProxyException(string? message, Exception? innerException)
: base(message, innerException)
{
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="ProxyException"/> class.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
/// <exception cref="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (0).</exception>
protected ProxyException(SerializationInfo info, StreamingContext context)
/// <inheritdoc/>
protected ProxyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif // NETFRAMEWORK
#endif
}
}
31 changes: 11 additions & 20 deletions src/Renci.SshNet/Common/ScpException.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
#if NETFRAMEWORK
using System.Runtime.Serialization;
#endif // NETFRAMEWORK
#nullable enable
using System;

namespace Renci.SshNet.Common
{
/// <summary>
/// The exception that is thrown when SCP error occurred.
/// The exception that is thrown when an SCP error occurs.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif // NETFRAMEWORK
#endif
public class ScpException : SshException
{
/// <summary>
Expand All @@ -23,34 +21,27 @@ public ScpException()
/// <summary>
/// Initializes a new instance of the <see cref="ScpException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public ScpException(string message)
/// <inheritdoc cref="Exception(string)" path="/param"/>
public ScpException(string? message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ScpException"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public ScpException(string message, Exception innerException)
/// <inheritdoc cref="Exception(string, Exception)" path="/param"/>
public ScpException(string? message, Exception? innerException)
: base(message, innerException)
{
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="ScpException"/> class.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
/// <exception cref="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (0). </exception>
protected ScpException(SerializationInfo info, StreamingContext context)
/// <inheritdoc/>
protected ScpException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif // NETFRAMEWORK
#endif
}
}
76 changes: 76 additions & 0 deletions src/Renci.SshNet/Common/SftpException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#nullable enable
using System;

using Renci.SshNet.Sftp;

namespace Renci.SshNet.Common
{
/// <summary>
/// The exception that is thrown when an error occurs in the SFTP layer.
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif
public class SftpException : SshException
{
/// <summary>
/// Gets the status code that is associated with this exception.
/// </summary>
public StatusCode StatusCode { get; }

/// <summary>
/// Initializes a new instance of the <see cref="SftpException"/> class.
/// </summary>
/// <param name="statusCode">The status code that indicates the error that occurred.</param>
public SftpException(StatusCode statusCode)
: this(statusCode, message: null, innerException: null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SftpException"/> class.
/// </summary>
/// <param name="statusCode">The status code that indicates the error that occurred.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
public SftpException(StatusCode statusCode, string? message)
: this(statusCode, message, innerException: null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SftpException"/> class.
/// </summary>
/// <param name="statusCode">The status code that indicates the error that occurred.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public SftpException(StatusCode statusCode, string? message, Exception? innerException)
: base(string.IsNullOrEmpty(message) ? GetDefaultMessage(statusCode) : message, innerException)
{
StatusCode = statusCode;
}

private protected static string GetDefaultMessage(StatusCode statusCode)
{
#pragma warning disable IDE0072 // Add missing cases
return statusCode switch
{
StatusCode.Ok => "The operation completed successfully.",
StatusCode.NoSuchFile => "A reference was made to a file that does not exist.",
StatusCode.PermissionDenied => "The user does not have sufficient permissions to perform the operation.",
StatusCode.Failure => "An error occurred, but no specific error code exists to describe the failure.",
StatusCode.BadMessage => "A badly formatted packet or SFTP protocol incompatibility was detected.",
StatusCode.OperationUnsupported => "An attempt was made to perform an operation which is not supported.",
_ => statusCode.ToString()
};
#pragma warning restore IDE0072 // Add missing cases
}

#if NETFRAMEWORK
/// <inheritdoc/>
protected SftpException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif
}
}
75 changes: 55 additions & 20 deletions src/Renci.SshNet/Common/SftpPathNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
#if NETFRAMEWORK
using System.Runtime.Serialization;
#endif // NETFRAMEWORK
#nullable enable
using System;

using Renci.SshNet.Sftp;

namespace Renci.SshNet.Common
{
Expand All @@ -10,47 +10,82 @@ namespace Renci.SshNet.Common
/// </summary>
#if NETFRAMEWORK
[Serializable]
#endif // NETFRAMEWORK
public class SftpPathNotFoundException : SshException
#endif
public class SftpPathNotFoundException : SftpException
{
private const StatusCode Code = StatusCode.NoSuchFile;

/// <summary>
/// Gets the path that cannot be found.
/// </summary>
/// <value>
/// The path that cannot be found, or <see langword="null"/> if no path was
/// passed to the constructor for this instance.
/// </value>
public string? Path { get; }

/// <summary>
/// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
/// </summary>
public SftpPathNotFoundException()
: this(message: null, path: null, innerException: null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
/// </summary>
/// <param name="message">The message.</param>
public SftpPathNotFoundException(string message)
: base(message)
/// <inheritdoc cref="Exception(string)" path="/param"/>
public SftpPathNotFoundException(string? message)
: this(message, path: null, innerException: null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public SftpPathNotFoundException(string message, Exception innerException)
: base(message, innerException)
/// <inheritdoc cref="Exception(string)" path="/param"/>
public SftpPathNotFoundException(string? message, string? path)
: this(message, path, innerException: null)
{
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
/// <exception cref="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (0). </exception>
protected SftpPathNotFoundException(SerializationInfo info, StreamingContext context)
/// <inheritdoc cref="Exception(string, Exception)" path="/param"/>
public SftpPathNotFoundException(string? message, Exception? innerException)
: this(message, path: null, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SftpPathNotFoundException"/> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="path">The path that cannot be found.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public SftpPathNotFoundException(string? message, string? path, Exception? innerException)
: base(Code, string.IsNullOrEmpty(message) ? GetDefaultMessage(path) : message, innerException)
{
Path = path;
}

private static string GetDefaultMessage(string? path)
{
var message = GetDefaultMessage(Code);

return path is not null
? $"{message} Path: '{path}'."
: message;
}

#if NETFRAMEWORK
/// <inheritdoc/>
protected SftpPathNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
}
#endif // NETFRAMEWORK
#endif
}
}
Loading