Knit corruption message triggered by KeyboardInterrupt
John Arbash Meinel
john at arbash-meinel.com
Wed Mar 14 20:36:01 GMT 2007
Martin Pool wrote:
> On 3/14/07, John Arbash Meinel <john at arbash-meinel.com> wrote:
>> Well, the code in question is handling GzipErrors, as well as other
>> errors.
>>
>> I would see at least IOError and OSError. However, I could also see just
>> separately catching KeyboardInterrupt with the standard:
>
> def _parse_record_header(self, version_id, raw_data):
> """Parse a record header for consistency.
>
> :return: the header and the decompressor stream.
> as (stream, header_record)
> """
> df = GzipFile(mode='rb', fileobj=StringIO(raw_data))
> try:
> rec = self._check_header(version_id, df.readline())
> except Exception, e:
> raise KnitCorrupt(self._filename,
> "While reading {%s} got %s(%s)"
> % (version_id, e.__class__.__name__, str(e)))
> return df, rec
>
> If you're wanting to report on GZipErrors then the gzip file should be
> opened inside the try block.
We can certainly move it in there. But GzipFile doesn't do any actual
processing in __init__. It just sets up the compression buffer, etc. It
isn't until you call a read*() function that it tries to read the file
and decompress anything.
>
> I think giving some context on what we were trying to read when we hit
> the error could be good.
Well, that was the point of raising with the version_id, and self._filename.
>
> Actually in some cases, such as this, it's incorrect and alarming to
> say there is knit corruption, we should just say "error reading knit"
> and let people draw their own conclusions.
>
I would be fine with having KnitReadError instead of KnitCorrupt. Though
it seems like it would be the same error, just with a different error
string (and name).
John
=:->
More information about the bazaar
mailing list