[tarfile] Difficultis catching an exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • boblatest@googlemail.com

    [tarfile] Difficultis catching an exception

    Hello,

    I'm trying to catch an "EOFError" exception that occurs when reading
    truncated tarfile. Here's my routine, and below that the callback
    trace. Note that although I'm trying to catch all TarFile exceptions,
    the tarfile.EOFErro r ecxeption, and the global EOFError exception, the
    program still falls through and fails.

    def query_archive(b atch_base):
    arc_name = os.path.join(ar chive_dir, 'B_'+batch_base +'.tar.bz2')
    sys.stderr.writ e('Archive: %s ' % arc_name)
    try:
    archive = tarfile.open(ar c_name, 'r:bz2')
    members = archive.getmemb ers()
    except tarfile.TarErro r, EOFError, tarfile.EOFErro r:
    sys.stderr.writ e("corrupt.\n ")
    db.execute('UPD ATE Archives SET Status=2 WHERE BatchBase=?',
    (batch_base, ))
    update_batchinf o(members, batch_base)
    return 0

    Archive: f:/wafermap_archiv e/B_48380.tar.bz2 Traceback (most recent
    call last):
    File "./wmap", line 11, in <module>
    task.run(comman d, args)
    File "/cygdrive/h/wafermaps/wmap_import.py" , line 142, in run
    query_archive(b atch_base)
    File "/cygdrive/h/wafermaps/wmap_import.py" , line 95, in
    query_archive
    members = archive.getmemb ers()
    File "/usr/lib/python2.5/tarfile.py", line 1282, in getmembers
    self._load() # all members, we first have to
    File "/usr/lib/python2.5/tarfile.py", line 2003, in _load
    tarinfo = self.next()
    File "/usr/lib/python2.5/tarfile.py", line 1809, in next
    self.fileobj.se ek(self.offset)
    EOFError: compressed file ended before the logical end-of-stream was
    detected
  • Wojtek Walczak

    #2
    Re: [tarfile] Difficultis catching an exception

    On Wed, 20 Aug 2008 02:07:33 -0700 (PDT), boblatest@googl email.com wrote:
    I'm trying to catch an "EOFError" exception that occurs when reading
    truncated tarfile. Here's my routine, and below that the callback
    trace. Note that although I'm trying to catch all TarFile exceptions,
    the tarfile.EOFErro r ecxeption, and the global EOFError exception, the
    program still falls through and fails.
    ....
    except tarfile.TarErro r, EOFError, tarfile.EOFErro r:
    ....

    Multiple exceptions should be parenthesized. BTW, are you sure
    your tarfile has EOFError attribute?
    Try this:

    ....
    except (tarfile.TarErr or, EOFError):
    ....

    --
    Regards,
    Wojtek Walczak,
    Cena domeny: 4999 PLN (do negocjacji). Możliwość kupna na raty od 624.88 PLN miesięcznie. Oferta sprzedaży znajduje się w serwisie Aftermarket.pl, największej giełdzie domen internetowych w Polsce.

    Comment

    Working...