diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-09-03 09:38:30 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-09-03 10:57:55 -0700 |
commit | 9239c1038562c9c16a49165e3293f8c895ef50c2 (patch) | |
tree | f20c38d94b30bd68279081df57b4e00948f35740 /org.eclipse.jgit.test/tst/org/eclipse/jgit/transport | |
parent | e6bd689d2c48efb4e6662ffca2fbdbc7570d2db1 (diff) | |
download | jgit-9239c1038562c9c16a49165e3293f8c895ef50c2.tar.gz jgit-9239c1038562c9c16a49165e3293f8c895ef50c2.zip |
ReceivePack: Rethrow exceptions caught during indexing
If we get an exception while indexing the incoming pack, its likely
a stream corruption. We already report an error to the client, but
we eat the stack trace, which makes debugging issues related to a
bug inside of JGit nearly impossible. Rethrow it under a new type
UnpackException, so embedding servers or applications can catch the
error and provide it to a human who might be able to forward such
traces onto a JGit developer for evaluation.
Change-Id: Icad41148bbc0c76f284c7033a195a6b51911beab
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/transport')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java index f89959c68c..edced2fbb7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java @@ -52,6 +52,8 @@ import java.util.HashMap; import java.util.Map; import java.util.zip.Deflater; +import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.errors.UnpackException; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Constants; @@ -240,7 +242,15 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { rp.setCheckReceivedObjects(true); rp.setCheckReferencedObjectsAreReachable(true); rp.setRefFilter(new HidePrivateFilter()); - rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); + try { + receive(rp, inBuf, outBuf); + fail("Expected UnpackException"); + } catch (UnpackException failed) { + Throwable err = failed.getCause(); + assertTrue(err instanceof MissingObjectException); + MissingObjectException moe = (MissingObjectException) err; + assertEquals(P, moe.getObjectId()); + } final PacketLineIn r = asPacketLineIn(outBuf); String master = r.readString(); @@ -254,6 +264,12 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { assertSame(PacketLineIn.END, r.readString()); } + private void receive(final ReceivePack rp, + final TemporaryBuffer.Heap inBuf, final TemporaryBuffer.Heap outBuf) + throws IOException { + rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); + } + public void testUsingHiddenDeltaBaseFails() throws Exception { final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); packHeader(pack, 1); @@ -275,7 +291,15 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { rp.setCheckReceivedObjects(true); rp.setCheckReferencedObjectsAreReachable(true); rp.setRefFilter(new HidePrivateFilter()); - rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); + try { + receive(rp, inBuf, outBuf); + fail("Expected UnpackException"); + } catch (UnpackException failed) { + Throwable err = failed.getCause(); + assertTrue(err instanceof MissingObjectException); + MissingObjectException moe = (MissingObjectException) err; + assertEquals(b, moe.getObjectId()); + } final PacketLineIn r = asPacketLineIn(outBuf); String master = r.readString(); @@ -316,7 +340,15 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { rp.setCheckReceivedObjects(true); rp.setCheckReferencedObjectsAreReachable(true); rp.setRefFilter(new HidePrivateFilter()); - rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); + try { + receive(rp, inBuf, outBuf); + fail("Expected UnpackException"); + } catch (UnpackException failed) { + Throwable err = failed.getCause(); + assertTrue(err instanceof MissingObjectException); + MissingObjectException moe = (MissingObjectException) err; + assertEquals(b, moe.getObjectId()); + } final PacketLineIn r = asPacketLineIn(outBuf); String master = r.readString(); @@ -358,7 +390,15 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { rp.setCheckReceivedObjects(true); rp.setCheckReferencedObjectsAreReachable(true); rp.setRefFilter(new HidePrivateFilter()); - rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); + try { + receive(rp, inBuf, outBuf); + fail("Expected UnpackException"); + } catch (UnpackException failed) { + Throwable err = failed.getCause(); + assertTrue(err instanceof MissingObjectException); + MissingObjectException moe = (MissingObjectException) err; + assertEquals(n, moe.getObjectId()); + } final PacketLineIn r = asPacketLineIn(outBuf); String master = r.readString(); @@ -397,7 +437,15 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase { rp.setCheckReceivedObjects(true); rp.setCheckReferencedObjectsAreReachable(true); rp.setRefFilter(new HidePrivateFilter()); - rp.receive(new ByteArrayInputStream(inBuf.toByteArray()), outBuf, null); + try { + receive(rp, inBuf, outBuf); + fail("Expected UnpackException"); + } catch (UnpackException failed) { + Throwable err = failed.getCause(); + assertTrue(err instanceof MissingObjectException); + MissingObjectException moe = (MissingObjectException) err; + assertEquals(t, moe.getObjectId()); + } final PacketLineIn r = asPacketLineIn(outBuf); String master = r.readString(); |