# Buggy code
def inspect_main(argv):
    # type: (List[unicode]) -> None
    """Debug functionality to print out an inventory"""
    if len(argv) < 1:
        print(
            "Print out an inventory file.\n"
            "Error: must specify local path or URL to an inventory file.",
            file=sys.stderr,
        )
        sys.exit(1)

    class MockConfig(object):
        intersphinx_timeout = None  # type: int
        tls_verify = False

    class MockApp(object):
        srcdir = ""
        config = MockConfig()

        def warn(self, msg):
            print(msg, file=sys.stderr)

    filename = argv[0]
    invdata = fetch_inventory(MockApp(), "", filename)  # type: ignore
    for key in sorted(invdata or {}):
        print(key)
        for entry, einfo in sorted(invdata[key].items()):
            print(
                "\t%-40s %s%s"
                % (entry, einfo[3] != "-" and "%-40s: " % einfo[3] or "", einfo[2])
            )


# Traceback (ValueError)
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/sphinx/ext/intersphinx.py", line 197, in fetch_inventory
invdata = InventoryFile.load(f, uri, join)
File "/usr/lib/python3.7/site-packages/sphinx/util/inventory.py", line 108, in load
raise ValueError('invalid inventory header: %s' % line)
ValueError: invalid inventory header:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3.7/site-packages/sphinx/ext/intersphinx.py", line 420, in <module>
inspect_main(argv=sys.argv[1:])  # type: ignore
File "/usr/lib/python3.7/site-packages/sphinx/ext/intersphinx.py", line 407, in inspect_main
invdata = fetch_inventory(MockApp(), '', filename)  # type: ignore
File "/usr/lib/python3.7/site-packages/sphinx/ext/intersphinx.py", line 199, in fetch_inventory
raise ValueError('unknown or unsupported inventory version: %r' % exc)
ValueError: ('intersphinx inventory %r not readable due to %s: %s', 'https://www.sphinx-doc.org', 'ValueError', ValueError(...))

# Fixed code
def inspect_main(argv):
    # type: (List[unicode]) -> None
    """Debug functionality to print out an inventory"""
    if len(argv) < 1:
        print(
            "Print out an inventory file.\n"
            "Error: must specify local path or URL to an inventory file.",
            file=sys.stderr,
        )
        sys.exit(1)

    class MockConfig(object):
        intersphinx_timeout = None  # type: int
        tls_verify = False

    class MockApp(object):
        srcdir = ""
        config = MockConfig()

        def warn(self, msg):
            print(msg, file=sys.stderr)

    try:
        filename = argv[0]
        invdata = fetch_inventory(MockApp(), "", filename)  # type: ignore
        for key in sorted(invdata or {}):
            print(key)
            for entry, einfo in sorted(invdata[key].items()):
                print(
                    "\t%-40s %s%s"
                    % (entry, einfo[3] != "-" and "%-40s: " % einfo[3] or "", einfo[2])
                )
    except ValueError as exc:
        print(exc.args[0] % exc.args[1:])
    except Exception as exc:
        print("Unknown error: %r" % exc)