Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 39777:b63dee7bd0d9
global: replace most uses of RevlogError with StorageError (API)
When catching errors in storage, we should be catching
StorageError instead of RevlogError. When throwing errors related
to storage, we shouldn't be using RevlogError unless we know
the error stemmed from revlogs. And we only reliably know that
if we're in revlog.py or are inheriting from a type defined in
revlog.py.
Differential Revision: https://phab.mercurial-scm.org/D4655
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 16:47:09 -0700 |
parents | 8f2c0d1b454c |
children | 5fe0b880200e |
comparison
equal
deleted
inserted
replaced
39776:cb65d4b7e429 | 39777:b63dee7bd0d9 |
---|---|
3446 value. | 3446 value. |
3447 | 3447 |
3448 The object has a ``decompress(data)`` method that decompresses | 3448 The object has a ``decompress(data)`` method that decompresses |
3449 data. The method will only be called if ``data`` begins with | 3449 data. The method will only be called if ``data`` begins with |
3450 ``revlogheader()``. The method should return the raw, uncompressed | 3450 ``revlogheader()``. The method should return the raw, uncompressed |
3451 data or raise a ``RevlogError``. | 3451 data or raise a ``StorageError``. |
3452 | 3452 |
3453 The object is reusable but is not thread safe. | 3453 The object is reusable but is not thread safe. |
3454 """ | 3454 """ |
3455 raise NotImplementedError() | 3455 raise NotImplementedError() |
3456 | 3456 |
3624 | 3624 |
3625 def decompress(self, data): | 3625 def decompress(self, data): |
3626 try: | 3626 try: |
3627 return zlib.decompress(data) | 3627 return zlib.decompress(data) |
3628 except zlib.error as e: | 3628 except zlib.error as e: |
3629 raise error.RevlogError(_('revlog decompress error: %s') % | 3629 raise error.StorageError(_('revlog decompress error: %s') % |
3630 stringutil.forcebytestr(e)) | 3630 stringutil.forcebytestr(e)) |
3631 | 3631 |
3632 def revlogcompressor(self, opts=None): | 3632 def revlogcompressor(self, opts=None): |
3633 return self.zlibrevlogcompressor() | 3633 return self.zlibrevlogcompressor() |
3634 | 3634 |
3635 compengines.register(_zlibengine()) | 3635 compengines.register(_zlibengine()) |
3836 pos = pos2 | 3836 pos = pos2 |
3837 # Frame should be exhausted, so no finish() API. | 3837 # Frame should be exhausted, so no finish() API. |
3838 | 3838 |
3839 return ''.join(chunks) | 3839 return ''.join(chunks) |
3840 except Exception as e: | 3840 except Exception as e: |
3841 raise error.RevlogError(_('revlog decompress error: %s') % | 3841 raise error.StorageError(_('revlog decompress error: %s') % |
3842 stringutil.forcebytestr(e)) | 3842 stringutil.forcebytestr(e)) |
3843 | 3843 |
3844 def revlogcompressor(self, opts=None): | 3844 def revlogcompressor(self, opts=None): |
3845 opts = opts or {} | 3845 opts = opts or {} |
3846 return self.zstdrevlogcompressor(self._module, | 3846 return self.zstdrevlogcompressor(self._module, |
3847 level=opts.get('level', 3)) | 3847 level=opts.get('level', 3)) |