471,873 Members | 1,009 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

[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.EOFError ecxeption, and the global EOFError exception, the
program still falls through and fails.

def query_archive(batch_base):
arc_name = os.path.join(archive_dir, 'B_'+batch_base+'.tar.bz2')
sys.stderr.write('Archive: %s ' % arc_name)
try:
archive = tarfile.open(arc_name, 'r:bz2')
members = archive.getmembers()
except tarfile.TarError, EOFError, tarfile.EOFError:
sys.stderr.write("corrupt.\n")
db.execute('UPDATE Archives SET Status=2 WHERE BatchBase=?',
(batch_base, ))
update_batchinfo(members, batch_base)
return 0

Archive: f:/wafermap_archive/B_48380.tar.bz2 Traceback (most recent
call last):
File "./wmap", line 11, in <module>
task.run(command, args)
File "/cygdrive/h/wafermaps/wmap_import.py", line 142, in run
query_archive(batch_base)
File "/cygdrive/h/wafermaps/wmap_import.py", line 95, in
query_archive
members = archive.getmembers()
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.seek(self.offset)
EOFError: compressed file ended before the logical end-of-stream was
detected
Aug 20 '08 #1
1 2481
On Wed, 20 Aug 2008 02:07:33 -0700 (PDT), bo*******@googlemail.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.EOFError ecxeption, and the global EOFError exception, the
program still falls through and fails.
....
except tarfile.TarError, EOFError, tarfile.EOFError:
....

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

....
except (tarfile.TarError, EOFError):
....

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
Aug 20 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Josh Smith | last post: by
8 posts views Thread by Jay Donnell | last post: by
8 posts views Thread by Dennis Hotson | last post: by
1 post views Thread by Beowulf | last post: by
1 post views Thread by Matthew Thorley | last post: by
7 posts views Thread by cmay | last post: by
6 posts views Thread by Terry Carroll | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.