~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-12 16:31:21 UTC
  • mfrom: (2329.1.2 knit_corrupt)
  • Revision ID: pqm@pqm.ubuntu.com-20070312163121-a8078e3704c91ffe
(John Arbash Meinel) raise more helpful errors when detecting Knit corruption.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1466
1466
                 as (stream, header_record)
1467
1467
        """
1468
1468
        df = GzipFile(mode='rb', fileobj=StringIO(raw_data))
1469
 
        rec = self._check_header(version_id, df.readline())
 
1469
        try:
 
1470
            rec = self._check_header(version_id, df.readline())
 
1471
        except Exception, e:
 
1472
            raise KnitCorrupt(self._filename,
 
1473
                              "While reading {%s} got %s(%s)"
 
1474
                              % (version_id, e.__class__.__name__, str(e)))
1470
1475
        return df, rec
1471
1476
 
1472
1477
    def _check_header(self, version_id, line):
1487
1492
        # 4168 calls to readlines in 330
1488
1493
        df = GzipFile(mode='rb', fileobj=StringIO(data))
1489
1494
 
1490
 
        record_contents = df.readlines()
 
1495
        try:
 
1496
            record_contents = df.readlines()
 
1497
        except Exception, e:
 
1498
            raise KnitCorrupt(self._filename,
 
1499
                              "While reading {%s} got %s(%s)"
 
1500
                              % (version_id, e.__class__.__name__, str(e)))
1491
1501
        header = record_contents.pop(0)
1492
1502
        rec = self._check_header(version_id, header)
1493
1503
 
1494
1504
        last_line = record_contents.pop()
1495
 
        assert len(record_contents) == int(rec[2])
 
1505
        if len(record_contents) != int(rec[2]):
 
1506
            raise KnitCorrupt(self._filename,
 
1507
                              'incorrect number of lines %s != %s'
 
1508
                              ' for version {%s}'
 
1509
                              % (len(record_contents), int(rec[2]),
 
1510
                                 version_id))
1496
1511
        if last_line != 'end %s\n' % rec[1]:
1497
1512
            raise KnitCorrupt(self._filename,
1498
1513
                              'unexpected version end line %r, wanted %r'