Skip to content

Propagate exceptions thrown by custom RpcSmartSubtransport #2164

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ public void CustomSmartSubtransportTest(string scheme, string url)
}
}

[Fact]
public void ExceptionPropogationTest()
{
var scd = BuildSelfCleaningDirectory();
var url = "https://github.com/libgit2/TestGitRepository";

SmartSubtransportRegistration<FailingSmartSubtransport> registration = null;

try
{
registration = GlobalSettings.RegisterSmartSubtransport<FailingSmartSubtransport>("https");
Assert.NotNull(registration);

var thrownException = Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.RootedDirectoryPath));
Assert.True(thrownException.Message.Contains("This is a Read Exception"), "Exception message did not contain expected reference.");
}
finally
{
GlobalSettings.UnregisterSmartSubtransport(registration);
}
}

//[Theory]
//[InlineData("https", "https://bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3")]
//public void CanUseCredentials(string scheme, string url, string user, string pass)
Expand Down Expand Up @@ -159,6 +181,32 @@ public void CannotUnregisterTwice()
GlobalSettings.UnregisterSmartSubtransport(httpRegistration));
}

private class FailingSmartSubtransport : RpcSmartSubtransport
{
protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
{
return new FailingSmartSubtransportStream(this);
}

private class FailingSmartSubtransportStream : SmartSubtransportStream
{
public FailingSmartSubtransportStream(FailingSmartSubtransport parent)
: base(parent)
{

}
public override int Read(Stream dataStream, long length, out long bytesRead)
{
throw new Exception("This is a Read Exception");
}

public override int Write(Stream dataStream, long length)
{
throw new NotImplementedException();
}
}
}

private class MockSmartSubtransport : RpcSmartSubtransport
{
protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
Expand Down
4 changes: 4 additions & 0 deletions LibGit2Sharp/SmartSubtransportStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ private static int SetError(SmartSubtransportStream stream, Exception caught)
{
errorCode = ((NativeException)ret).ErrorCode;
}
else
{
Proxy.git_error_set_str(GitErrorCategory.Unknown, caught);
}

return (int)errorCode;
}
Expand Down
Loading