# Buggy code
def handle_name(state, token):
    """Function for handling name tokens"""
    typ = "NAME"
    if state["pymode"][-1][0]:
        if token.string in kwmod.kwlist:
            typ = token.string.upper()
        state["last"] = token
        yield _new_token(typ, token.string, token.start)
    else:
        prev = state["last"]
        state["last"] = token
        has_whitespace = prev.end != token.start
        if token.string == "and" and has_whitespace:
            yield _new_token("AND", token.string, token.start)
        elif token.string == "or" and has_whitespace:
            yield _new_token("OR", token.string, token.start)
        else:
            yield _new_token("NAME", token.string, token.start)


# Traceback (FileNotFoundError)
jbleger@gertrude:~$ XONSH_DEBUG=1 xonsh
jbleger@gertrude ~ $ cd /tmp/
jbleger@gertrude /tmp $ mkdir -p a/path/and/another/one
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
xonsh: subprocess mode: command not found: /another/one
jbleger@gertrude /tmp [1] $ $XONSH_SHOW_TRACEBACK=True
jbleger@gertrude /tmp $ mkdir -p a/path/and/another/one
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/home/jbleger/.local/lib/python3.6/site-packages/xonsh/built_ins.py", line 550, in _run_binary
p = self.cls(self.cmd, bufsize=bufsize, **kwargs)
File "/home/jbleger/.local/lib/python3.6/site-packages/xonsh/proc.py", line 582, in __init__
*args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/another/one': '/another/one'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/jbleger/.local/lib/python3.6/site-packages/xonsh/proc.py", line 1843, in __init__
proc = spec.run(pipeline_group=pipeline_group)
File "/home/jbleger/.local/lib/python3.6/site-packages/xonsh/built_ins.py", line 540, in run
p = self._run_binary(kwargs)
File "/home/jbleger/.local/lib/python3.6/site-packages/xonsh/built_ins.py", line 561, in _run_binary
raise XonshError(e)
xonsh.tools.XonshError: xonsh: subprocess mode: command not found: /another/one

# Fixed code
def handle_name(state, token):
    """Function for handling name tokens"""
    typ = "NAME"
    state["last"] = token
    needs_whitespace = token.string in NEED_WHITESPACE
    has_whitespace = needs_whitespace and RE_NEED_WHITESPACE.match(
        token.line[max(0, token.start[1] - 1) :]
    )
    if state["pymode"][-1][0]:
        if needs_whitespace and not has_whitespace:
            pass
        elif token.string in kwmod.kwlist:
            typ = token.string.upper()
        yield _new_token(typ, token.string, token.start)
    else:
        if has_whitespace and token.string == "and":
            yield _new_token("AND", token.string, token.start)
        elif has_whitespace and token.string == "or":
            yield _new_token("OR", token.string, token.start)
        else:
            yield _new_token("NAME", token.string, token.start)