Crashes when git isn't present

Bug #1521541 reported by Thomas Goirand
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslosphinx
Fix Released
High
Doug Hellmann

Bug Description

oslosphinx tries to be smart has has the below code:

def _guess_cgit_link():
    try:
        git_remote = subprocess.check_output(
            ['git', 'config', '--local', '--get', 'remote.origin.url']
        )
    except subprocess.CalledProcessError:
        return None
    else:
        parsed = parse.urlparse(git_remote)
        return CGIT_BASE + parsed.path.lstrip('/')

Unfortunately, when building a package which uses oslosphinx, the exception isn't caught at all, and it crashes the build. For example, when trying to build olso.i18n, here's the result:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/sphinx/cmdline.py", line 239, in main
    opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
  File "/usr/lib/python2.7/dist-packages/sphinx/application.py", line 143, in __init__
    self.setup_extension(extension)
  File "/usr/lib/python2.7/dist-packages/sphinx/application.py", line 440, in setup_extension
    ext_meta = mod.setup(self)
  File "/usr/lib/python2.7/dist-packages/oslosphinx/__init__.py", line 67, in setup
    cgit_link = _guess_cgit_link()
  File "/usr/lib/python2.7/dist-packages/oslosphinx/__init__.py", line 26, in _guess_cgit_link
    ['git', 'config', '--local', '--get', 'remote.origin.url']
  File "/usr/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Replacing "except subprocess.CalledProcessError:" by "except:" (to catch all exception), it then works. Though probably we want to fix it catching the correct exception.

Note that when building packages using sbuild for distributions, git isn't present indeed, so catching the exception is really what should be done, but properly.

Changed in oslosphinx:
assignee: nobody → Doug Hellmann (doug-hellmann)
importance: Undecided → High
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslosphinx (master)

Fix proposed to branch: master
Review: https://review.openstack.org/251955

Changed in oslosphinx:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslosphinx (master)

Reviewed: https://review.openstack.org/251955
Committed: https://git.openstack.org/cgit/openstack/oslosphinx/commit/?id=f8d71ac5ad023a32cbbe04e109eb2793433ee558
Submitter: Jenkins
Branch: master

commit f8d71ac5ad023a32cbbe04e109eb2793433ee558
Author: Doug Hellmann <email address hidden>
Date: Tue Dec 1 16:34:54 2015 +0000

    trap errors from git not being present

    subprocess raises OSError if the command it is asked to run isn't found,
    so trap that as well as the subprocess-specific error we were already
    catching.

    Change-Id: Ieb9c7f3ccc307250847104a7f97cfa28603fcf5d
    Closes-Bug: #1521541

Changed in oslosphinx:
status: In Progress → Fix Committed
Changed in oslosphinx:
milestone: none → 4.1.0
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.