Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/testing/storage.py @ 39792:cb65d4b7e429
error: introduce StorageError
Errors in revlogs are often represented by RevlogError. It's fine
for revlogs to raise a revlog-specific exception. But in the context
of multiple storage backends, it doesn't make sense to be throwing or
catching an exception with "revlog" in its name when revlogs may not
even be in play.
This commit introduces a new generic StorageError type for representing
errors in the storage layer.
RevlogError is an instance of this type.
Interface documentation and tests referencing RevlogError has been
updated to specify StorageError should be used.
.. api::
``error.StorageError`` has been introduced to represent errors in
storage. It should be used in place of ``error.RevlogError`` unless
the error is known to come from a revlog.
Differential Revision: https://phab.mercurial-scm.org/D4654
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 16:45:13 -0700 |
parents | ae531f5e583c |
children | 979e9f124caa |
comparison
equal
deleted
inserted
replaced
39791:974592474dee | 39792:cb65d4b7e429 |
---|---|
420 continue | 420 continue |
421 | 421 |
422 with self.assertRaises(IndexError): | 422 with self.assertRaises(IndexError): |
423 f.size(i) | 423 f.size(i) |
424 | 424 |
425 with self.assertRaises(error.RevlogError): | 425 with self.assertRaises(error.StorageError): |
426 f.checkhash(b'', nullid) | 426 f.checkhash(b'', nullid) |
427 | 427 |
428 with self.assertRaises(error.LookupError): | 428 with self.assertRaises(error.LookupError): |
429 f.checkhash(b'', b'\x01' * 20) | 429 f.checkhash(b'', b'\x01' * 20) |
430 | 430 |
525 f.size(1) | 525 f.size(1) |
526 | 526 |
527 f.checkhash(fulltext, node) | 527 f.checkhash(fulltext, node) |
528 f.checkhash(fulltext, node, nullid, nullid) | 528 f.checkhash(fulltext, node, nullid, nullid) |
529 | 529 |
530 with self.assertRaises(error.RevlogError): | 530 with self.assertRaises(error.StorageError): |
531 f.checkhash(fulltext + b'extra', node) | 531 f.checkhash(fulltext + b'extra', node) |
532 | 532 |
533 with self.assertRaises(error.RevlogError): | 533 with self.assertRaises(error.StorageError): |
534 f.checkhash(fulltext, node, b'\x01' * 20, nullid) | 534 f.checkhash(fulltext, node, b'\x01' * 20, nullid) |
535 | 535 |
536 with self.assertRaises(error.RevlogError): | 536 with self.assertRaises(error.StorageError): |
537 f.checkhash(fulltext, node, nullid, b'\x01' * 20) | 537 f.checkhash(fulltext, node, nullid, b'\x01' * 20) |
538 | 538 |
539 self.assertEqual(f.revision(node), fulltext) | 539 self.assertEqual(f.revision(node), fulltext) |
540 self.assertEqual(f.revision(node, raw=True), fulltext) | 540 self.assertEqual(f.revision(node, raw=True), fulltext) |
541 | 541 |
601 f.checkhash(fulltext0, node0) | 601 f.checkhash(fulltext0, node0) |
602 f.checkhash(fulltext1, node1) | 602 f.checkhash(fulltext1, node1) |
603 f.checkhash(fulltext1, node1, node0, nullid) | 603 f.checkhash(fulltext1, node1, node0, nullid) |
604 f.checkhash(fulltext2, node2, node1, nullid) | 604 f.checkhash(fulltext2, node2, node1, nullid) |
605 | 605 |
606 with self.assertRaises(error.RevlogError): | 606 with self.assertRaises(error.StorageError): |
607 f.checkhash(fulltext1, b'\x01' * 20) | 607 f.checkhash(fulltext1, b'\x01' * 20) |
608 | 608 |
609 with self.assertRaises(error.RevlogError): | 609 with self.assertRaises(error.StorageError): |
610 f.checkhash(fulltext1 + b'extra', node1, node0, nullid) | 610 f.checkhash(fulltext1 + b'extra', node1, node0, nullid) |
611 | 611 |
612 with self.assertRaises(error.RevlogError): | 612 with self.assertRaises(error.StorageError): |
613 f.checkhash(fulltext1, node1, node0, node0) | 613 f.checkhash(fulltext1, node1, node0, node0) |
614 | 614 |
615 self.assertEqual(f.revision(node0), fulltext0) | 615 self.assertEqual(f.revision(node0), fulltext0) |
616 self.assertEqual(f.revision(node0, raw=True), fulltext0) | 616 self.assertEqual(f.revision(node0, raw=True), fulltext0) |
617 self.assertEqual(f.revision(node1), fulltext1) | 617 self.assertEqual(f.revision(node1), fulltext1) |
850 | 850 |
851 def testaddrevisionbadnode(self): | 851 def testaddrevisionbadnode(self): |
852 f = self._makefilefn() | 852 f = self._makefilefn() |
853 with self._maketransactionfn() as tr: | 853 with self._maketransactionfn() as tr: |
854 # Adding a revision with bad node value fails. | 854 # Adding a revision with bad node value fails. |
855 with self.assertRaises(error.RevlogError): | 855 with self.assertRaises(error.StorageError): |
856 f.addrevision(b'foo', tr, 0, nullid, nullid, node=b'\x01' * 20) | 856 f.addrevision(b'foo', tr, 0, nullid, nullid, node=b'\x01' * 20) |
857 | 857 |
858 def testaddrevisionunknownflag(self): | 858 def testaddrevisionunknownflag(self): |
859 f = self._makefilefn() | 859 f = self._makefilefn() |
860 with self._maketransactionfn() as tr: | 860 with self._maketransactionfn() as tr: |
861 for i in range(15, 0, -1): | 861 for i in range(15, 0, -1): |
862 if (1 << i) & ~revlog.REVIDX_KNOWN_FLAGS: | 862 if (1 << i) & ~revlog.REVIDX_KNOWN_FLAGS: |
863 flags = 1 << i | 863 flags = 1 << i |
864 break | 864 break |
865 | 865 |
866 with self.assertRaises(error.RevlogError): | 866 with self.assertRaises(error.StorageError): |
867 f.addrevision(b'foo', tr, 0, nullid, nullid, flags=flags) | 867 f.addrevision(b'foo', tr, 0, nullid, nullid, flags=flags) |
868 | 868 |
869 def testaddgroupsimple(self): | 869 def testaddgroupsimple(self): |
870 f = self._makefilefn() | 870 f = self._makefilefn() |
871 | 871 |
889 deltas = [ | 889 deltas = [ |
890 (b'\x01' * 20, nullid, nullid, nullid, nullid, delta0, 0), | 890 (b'\x01' * 20, nullid, nullid, nullid, nullid, delta0, 0), |
891 ] | 891 ] |
892 | 892 |
893 with self._maketransactionfn() as tr: | 893 with self._maketransactionfn() as tr: |
894 with self.assertRaises(error.RevlogError): | 894 with self.assertRaises(error.StorageError): |
895 f.addgroup(deltas, linkmapper, tr, addrevisioncb=cb) | 895 f.addgroup(deltas, linkmapper, tr, addrevisioncb=cb) |
896 | 896 |
897 node0 = f.add(fulltext0, None, tr, 0, nullid, nullid) | 897 node0 = f.add(fulltext0, None, tr, 0, nullid, nullid) |
898 | 898 |
899 f = self._makefilefn() | 899 f = self._makefilefn() |