# Buggy code
def opengl_vendor():  # pragma: no cover
    """Get the OpenGL vendor used.

    This returns a string such as 'nouveau' or
    'Intel Open Source Technology Center'; or None if the vendor can't be
    determined.
    """
    assert QApplication.instance()

    old_context = QOpenGLContext.currentContext()
    old_surface = None if old_context is None else old_context.surface()

    surface = QOffscreenSurface()
    surface.create()

    ctx = QOpenGLContext()
    ok = ctx.create()
    if not ok:
        log.init.debug("opengl_vendor: Creating context failed!")
        return None

    ok = ctx.makeCurrent(surface)
    if not ok:
        log.init.debug("opengl_vendor: Making context current failed!")
        return None

    try:
        if ctx.isOpenGLES():
            # Can't use versionFunctions there
            return None

        vp = QOpenGLVersionProfile()
        vp.setVersion(2, 0)

        vf = ctx.versionFunctions(vp)
        if vf is None:
            log.init.debug("opengl_vendor: Getting version functions failed!")
            return None

        return vf.glGetString(vf.GL_VENDOR)
    finally:
        ctx.doneCurrent()
        if old_context and old_surface:
            old_context.makeCurrent(old_surface)


# Traceback (ModuleNotFoundError)
09:30:15 ERROR: Uncaught exception
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/home/novel/code/qutebrowser/qutebrowser/__main__.py", line 29, in <module>
sys.exit(qutebrowser.qutebrowser.main())
File "/usr/home/novel/code/qutebrowser/qutebrowser/qutebrowser.py", line 188, in main
return app.run(args)
File "/usr/home/novel/code/qutebrowser/qutebrowser/app.py", line 138, in run
init(args, crash_handler)
File "/usr/home/novel/code/qutebrowser/qutebrowser/app.py", line 164, in init
_init_modules(args, crash_handler)
File "/usr/home/novel/code/qutebrowser/qutebrowser/app.py", line 427, in _init_modules
backendproblem.init()
File "/usr/home/novel/code/qutebrowser/qutebrowser/misc/backendproblem.py", line 370, in init
_handle_nouveau_graphics()
File "/usr/home/novel/code/qutebrowser/qutebrowser/misc/backendproblem.py", line 179, in _handle_nouveau_graphics
if version.opengl_vendor() != 'nouveau':
File "/usr/home/novel/code/qutebrowser/qutebrowser/utils/version.py", line 456, in opengl_vendor
vf = ctx.versionFunctions(vp)
ModuleNotFoundError: No module named 'PyQt5._QOpenGLFunctions_2_0'
09:30:15 ERROR: Error while getting history: 'command-history'
Traceback (most recent call last):
File "/usr/home/novel/code/qutebrowser/qutebrowser/misc/crashsignal.py", line 190, in _get_exception_info
cmd_history = objreg.get('command-history')[-5:]
File "/usr/home/novel/code/qutebrowser/qutebrowser/utils/objreg.py", line 229, in get
return reg[name]
File "/usr/local/lib/python3.6/collections/__init__.py", line 991, in __getitem__
raise KeyError(key)
KeyError: 'command-history'

# Fixed code
def opengl_vendor():  # pragma: no cover
    """Get the OpenGL vendor used.

    This returns a string such as 'nouveau' or
    'Intel Open Source Technology Center'; or None if the vendor can't be
    determined.
    """
    assert QApplication.instance()

    old_context = QOpenGLContext.currentContext()
    old_surface = None if old_context is None else old_context.surface()

    surface = QOffscreenSurface()
    surface.create()

    ctx = QOpenGLContext()
    ok = ctx.create()
    if not ok:
        log.init.debug("opengl_vendor: Creating context failed!")
        return None

    ok = ctx.makeCurrent(surface)
    if not ok:
        log.init.debug("opengl_vendor: Making context current failed!")
        return None

    try:
        if ctx.isOpenGLES():
            # Can't use versionFunctions there
            return None

        vp = QOpenGLVersionProfile()
        vp.setVersion(2, 0)

        try:
            vf = ctx.versionFunctions(vp)
        except ImportError as e:
            log.init.debug(
                "opengl_vendor: Importing version functions failed: {}".format(e)
            )
            return None

        if vf is None:
            log.init.debug("opengl_vendor: Getting version functions failed!")
            return None

        return vf.glGetString(vf.GL_VENDOR)
    finally:
        ctx.doneCurrent()
        if old_context and old_surface:
            old_context.makeCurrent(old_surface)