Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ExceptionDispatchInfo in more places #1182

Merged
merged 2 commits into from
Sep 23, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Threading;

using Renci.SshNet.Abstractions;
Expand Down Expand Up @@ -78,7 +79,7 @@ public override AuthenticationResult Authenticate(Session session)

if (_exception != null)
{
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
}

return _authenticationResult;
Expand Down
3 changes: 2 additions & 1 deletion src/Renci.SshNet/PasswordAuthenticationMethod.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;

Expand Down Expand Up @@ -114,7 +115,7 @@ public override AuthenticationResult Authenticate(Session session)

if (_exception != null)
{
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
}

return _authenticationResult;
Expand Down
5 changes: 3 additions & 2 deletions src/Renci.SshNet/Sftp/SftpFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.ExceptionServices;
using System.Threading;

using Renci.SshNet.Abstractions;
Expand Down Expand Up @@ -80,7 +81,7 @@ public byte[] Read()

if (_exception is not null)
{
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
}

if (_isEndOfFileRead)
Expand All @@ -102,7 +103,7 @@ public byte[] Read()
// throw when exception occured in read-ahead, or the current instance is already disposed
if (_exception != null)
{
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
}

var data = nextChunk.Data;
Expand Down
4 changes: 3 additions & 1 deletion src/Renci.SshNet/SshCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;

Expand Down Expand Up @@ -483,7 +484,8 @@ private void WaitOnHandle(WaitHandle waitHandle)
switch (signaledElement)
{
case 0:
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
break;
case 1:
// Specified waithandle was signaled
break;
Expand Down
13 changes: 9 additions & 4 deletions src/Renci.SshNet/SubsystemSession.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Runtime.ExceptionServices;
using System.Threading;

using Renci.SshNet.Abstractions;
Expand Down Expand Up @@ -241,7 +242,8 @@ public void WaitOnHandle(WaitHandle waitHandle, int millisecondsTimeout)
switch (result)
{
case 0:
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
break;
case 1:
throw new SshException("Connection was closed by the server.");
case 2:
Expand Down Expand Up @@ -286,7 +288,8 @@ public bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout)
switch (result)
{
case 0:
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
return false; // unreached
case 1:
throw new SshException("Connection was closed by the server.");
case 2:
Expand Down Expand Up @@ -340,7 +343,8 @@ public int WaitAny(WaitHandle waitHandle1, WaitHandle waitHandle2, int milliseco
switch (result)
{
case 0:
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
return -1; // unreached
case 1:
throw new SshException("Connection was closed by the server.");
case 2:
Expand Down Expand Up @@ -377,7 +381,8 @@ public int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout)
switch (result)
{
case 0:
throw _exception;
ExceptionDispatchInfo.Capture(_exception).Throw();
return -1; // unreached
case 1:
throw new SshException("Connection was closed by the server.");
case 2:
Expand Down