Skip to content

Commit 027316e

Browse files
committed
Propogate exceptions thrown by custom SmartSubtransport
1 parent 50d6978 commit 027316e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ public void CustomSmartSubtransportTest(string scheme, string url)
7777
}
7878
}
7979

80+
[Fact]
81+
public void ExceptionPropogationTest()
82+
{
83+
var scd = BuildSelfCleaningDirectory();
84+
var url = "https://github.com/libgit2/TestGitRepository";
85+
86+
SmartSubtransportRegistration<FailingSmartSubtransport> registration = null;
87+
88+
try
89+
{
90+
registration = GlobalSettings.RegisterSmartSubtransport<FailingSmartSubtransport>("https");
91+
Assert.NotNull(registration);
92+
93+
var thrownException = Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.RootedDirectoryPath));
94+
Assert.True(thrownException.Message.Contains("This is a Read Exception"), "Exception message did not contain expected reference.");
95+
}
96+
finally
97+
{
98+
GlobalSettings.UnregisterSmartSubtransport(registration);
99+
}
100+
}
101+
80102
//[Theory]
81103
//[InlineData("https", "https://bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3")]
82104
//public void CanUseCredentials(string scheme, string url, string user, string pass)
@@ -159,6 +181,32 @@ public void CannotUnregisterTwice()
159181
GlobalSettings.UnregisterSmartSubtransport(httpRegistration));
160182
}
161183

184+
private class FailingSmartSubtransport : RpcSmartSubtransport
185+
{
186+
protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
187+
{
188+
return new FailingSmartSubtransportStream(this);
189+
}
190+
191+
private class FailingSmartSubtransportStream : SmartSubtransportStream
192+
{
193+
public FailingSmartSubtransportStream(FailingSmartSubtransport parent)
194+
: base(parent)
195+
{
196+
197+
}
198+
public override int Read(Stream dataStream, long length, out long bytesRead)
199+
{
200+
throw new Exception("This is a Read Exception");
201+
}
202+
203+
public override int Write(Stream dataStream, long length)
204+
{
205+
throw new NotImplementedException();
206+
}
207+
}
208+
}
209+
162210
private class MockSmartSubtransport : RpcSmartSubtransport
163211
{
164212
protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)

LibGit2Sharp/SmartSubtransportStream.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ private static int SetError(SmartSubtransportStream stream, Exception caught)
119119
{
120120
errorCode = ((NativeException)ret).ErrorCode;
121121
}
122+
else
123+
{
124+
Proxy.git_error_set_str(GitErrorCategory.Unknown, caught);
125+
}
122126

123127
return (int)errorCode;
124128
}

0 commit comments

Comments
 (0)