OSError from _readdir is printed without a useful filename

Bug #338653 reported by Martin Pool
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Martin Pool

Bug Description

When an OSError occurs, eg because of an environmental problem, bzr tends to print it without the filename, which makes it harder to debug.

The python error has a filename attribute; we should print it.

Example:

No handlers could be found for logger "bzr"
bzr: ERROR: exceptions.OSError: [Errno 13] Permission denied

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 896, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 842, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 542, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 856, in ignore_pipe
    result = func(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/builtins.py", line 241, in run
    show_pending=(not no_pending), verbose=verbose)
  File "/usr/lib/python2.5/site-packages/bzrlib/status.py", line 118, in show_tree_status
    want_unversioned=want_unversioned)
  File "/usr/lib/python2.5/site-packages/bzrlib/tree.py", line 95, in changes_from
    want_unversioned=want_unversioned,
  File "/usr/lib/python2.5/site-packages/bzrlib/decorators.py", line 138, in read_locked
    result = unbound(self, *args, **kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/tree.py", line 877, in compare
    want_unversioned=want_unversioned)
  File "/usr/lib/python2.5/site-packages/bzrlib/delta.py", line 230, in _compare_trees
    want_unversioned=want_unversioned):
  File "_dirstate_helpers_c.pyx", line 1347, in _dirstate_helpers_c.ProcessEntryC.__next__
  File "_dirstate_helpers_c.pyx", line 1613, in _dirstate_helpers_c.ProcessEntryC._iter_next
  File "_dirstate_helpers_c.pyx", line 1772, in _dirstate_helpers_c.ProcessEntryC._loop_one_block
  File "/usr/lib/python2.5/site-packages/bzrlib/osutils.py", line 1401, in _walkdirs_utf8
    dirblock = sorted(read_dir(relroot, top))
  File "_readdir_pyx.pyx", line 237, in _readdir_pyx.UTF8DirReader.read_dir
  File "_readdir_pyx.pyx", line 303, in _readdir_pyx._read_dir
OSError: [Errno 13] Permission denied

Revision history for this message
Martin Pool (mbp) wrote :

Reported by Mez on irc.

Changed in bzr:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Martin Pool (mbp) wrote :

We actually have a test_format_os_error that tries to handle this, but it actually generates an IOError and they don't behave in quite the same way. An IOError's message includes the filename, but OSError does not, at least in python2.6.

Revision history for this message
Martin Pool (mbp) wrote :

I can't reproduce this with general handling of OSError and IOError, in fact in some cases we seem to get too many filenames:

% ./bzr st /tmp/a/a/
bzr: ERROR: Permission denied: "/tmp/a/a/.bzr/branch-format": [Errno 13] Permission denied: u'/tmp/a/a/.bzr/branch-format'

It might be specific to OSError and IOError raised from inside the dirstate helpers.

Revision history for this message
Martin Pool (mbp) wrote :

And that's correct, the C and Pyrex code needs to provide the filename and does not.

295 if path != "" and path != '.':
296 # we change into the requested directory before reading, and back at the
297 # end, because that turns out to make the stat calls measurably faster than
298 # passing full paths every time.
299 orig_dir_fd = open(".", O_RDONLY, 0)
300 if orig_dir_fd == -1:
301 raise OSError(errno, strerror(errno))
302 if -1 == chdir(path):
303 raise OSError(errno, strerror(errno))

Revision history for this message
Martin Pool (mbp) wrote :

Patch posted.

Changed in bzr:
assignee: nobody → mbp
status: Confirmed → Fix Committed
Jelmer Vernooij (jelmer)
Changed in bzr:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.