# Buggy code
def _starts_debugging(func):
    def debug(address, **kwargs):
        if _settrace.called:
            raise RuntimeError("this process already has a debug adapter")

        try:
            _, port = address
        except Exception:
            port = address
            address = ("127.0.0.1", port)
        try:
            port.__index__()  # ensure it's int-like
        except Exception:
            raise ValueError("expected port or (host, port)")
        if not (0 <= port < 2**16):
            raise ValueError("invalid port number")

        ensure_logging()
        log.debug("{0}({1!r}, **{2!r})", func.__name__, address, kwargs)
        log.info("Initial debug configuration: {0!j}", _config)

        qt_mode = _config.get("qt", "none")
        if qt_mode != "none":
            pydevd.enable_qt_support(qt_mode)

        settrace_kwargs = {
            "suspend": False,
            "patch_multiprocessing": _config.get("subProcess", True),
        }

        debugpy_path = os.path.dirname(absolute_path(debugpy.__file__))
        settrace_kwargs["dont_trace_start_patterns"] = (debugpy_path,)
        settrace_kwargs["dont_trace_end_patterns"] = ("debugpy_launcher.py",)

        try:
            return func(address, settrace_kwargs, **kwargs)
        except Exception:
            log.reraise_exception("{0}() failed:", func.__name__, level="info")

    return debug


# Traceback (IOError)
Traceback (most recent call last):
File "c:/Users/kanadig/.vscode/extensions/ms-python.python-2019.5.17059/pythonFiles/ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "C:\GIT\ptvsd\src\ptvsd\__main__.py", line 434, in main
run()
File "C:\GIT\ptvsd\src\ptvsd\__main__.py", line 312, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Python27\lib\runpy.py", line 251, in run_path
code = _get_code_from_file(path_name)
File "C:\Python27\lib\runpy.py", line 227, in _get_code_from_file
with open(fname, "rb") as f:
IOError: [Errno 22] invalid mode ('rb') or filename: 'c:\\GIT\\pyscratch2\\??\\experiment.py'

# Fixed code
def _starts_debugging(func):
    def debug(address, **kwargs):
        if _settrace.called:
            raise RuntimeError("this process already has a debug adapter")

        try:
            _, port = address
        except Exception:
            port = address
            address = ("127.0.0.1", port)
        try:
            port.__index__()  # ensure it's int-like
        except Exception:
            raise ValueError("expected port or (host, port)")
        if not (0 <= port < 2**16):
            raise ValueError("invalid port number")

        ensure_logging()
        log.debug("{0}({1!r}, **{2!r})", func.__name__, address, kwargs)
        log.info("Initial debug configuration: {0!j}", _config)

        qt_mode = _config.get("qt", "none")
        if qt_mode != "none":
            pydevd.enable_qt_support(qt_mode)

        settrace_kwargs = {
            "suspend": False,
            "patch_multiprocessing": _config.get("subProcess", True),
        }

        debugpy_path = os.path.dirname(absolute_path(debugpy.__file__))
        settrace_kwargs["dont_trace_start_patterns"] = (debugpy_path,)
        settrace_kwargs["dont_trace_end_patterns"] = (str("debugpy_launcher.py"),)

        try:
            return func(address, settrace_kwargs, **kwargs)
        except Exception:
            log.reraise_exception("{0}() failed:", func.__name__, level="info")

    return debug