# Buggy code
def convert_macro_arg(raw_arg, kind, glbs, locs, *, name="<arg>", macroname="<macro>"):
    """Converts a string macro argument based on the requested kind.

    Parameters
    ----------
    raw_arg : str
        The str reprensetaion of the macro argument.
    kind : object
        A flag or type representing how to convert the argument.
    glbs : Mapping
        The globals from the call site.
    locs : Mapping or None
        The locals from the call site.
    name : str, optional
        The macro argument name.
    macroname : str, optional
        The name of the macro itself.

    Returns
    -------
    The converted argument.
    """
    # munge kind and mode to start
    mode = None
    if isinstance(kind, cabc.Sequence) and not isinstance(kind, str):
        # have (kind, mode) tuple
        kind, mode = kind
    if isinstance(kind, str):
        kind = _convert_kind_flag(kind)
    if kind is str or kind is None:
        return raw_arg  # short circut since there is nothing else to do
    # select from kind and convert
    execer = builtins.__xonsh_execer__
    filename = macroname + "(" + name + ")"
    if kind is AST:
        ctx = set(dir(builtins)) | set(glbs.keys())
        if locs is not None:
            ctx |= set(locs.keys())
        mode = mode or "eval"
        arg = execer.parse(raw_arg, ctx, mode=mode, filename=filename)
    elif kind is types.CodeType or kind is compile:
        mode = mode or "eval"
        arg = execer.compile(
            raw_arg, mode=mode, glbs=glbs, locs=locs, filename=filename
        )
    elif kind is eval:
        arg = execer.eval(raw_arg, glbs=glbs, locs=locs, filename=filename)
    elif kind is exec:
        mode = mode or "exec"
        if not raw_arg.endswith("\n"):
            raw_arg += "\n"
        arg = execer.exec(raw_arg, mode=mode, glbs=glbs, locs=locs, filename=filename)
    elif kind is type:
        arg = type(execer.eval(raw_arg, glbs=glbs, locs=locs, filename=filename))
    else:
        msg = "kind={0!r} and mode={1!r} was not recongnized for macro argument {2!r}"
        raise TypeError(msg.format(kind, mode, name))
    return arg


# Traceback (ProcessLookupError)
ls | more
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 17380, in default
run_compiled_code(code, self.ctx, None, 'single')
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 1964, in run_compiled_code
func(code, glb, loc)
File "<xonsh-code>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 16159, in subproc_captured_hiddenobject
return run_subproc(cmds, captured='hiddenobject')
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 16127, in run_subproc
command.end()
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 11116, in end
for _ in self.tee_stdout():
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 11041, in tee_stdout
for line in self.iterraw():
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 10940, in iterraw
wait_for_active_job()
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 3694, in wait_for_active_job
_continue(active_task)
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 3607, in _continue
_send_signal(job, signal.SIGCONT)
File "/usr/local/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 3542, in _send_signal
os.kill(pid, signal)
ProcessLookupError: [Errno 3] No such process

# Fixed code
def convert_macro_arg(raw_arg, kind, glbs, locs, *, name="<arg>", macroname="<macro>"):
    """Converts a string macro argument based on the requested kind.

    Parameters
    ----------
    raw_arg : str
        The str reprensetaion of the macro argument.
    kind : object
        A flag or type representing how to convert the argument.
    glbs : Mapping
        The globals from the call site.
    locs : Mapping or None
        The locals from the call site.
    name : str, optional
        The macro argument name.
    macroname : str, optional
        The name of the macro itself.

    Returns
    -------
    The converted argument.
    """
    # munge kind and mode to start
    mode = None
    if isinstance(kind, cabc.Sequence) and not isinstance(kind, str):
        # have (kind, mode) tuple
        kind, mode = kind
    if isinstance(kind, str):
        kind = _convert_kind_flag(kind)
    if kind is str or kind is None:
        return raw_arg  # short circut since there is nothing else to do
    # select from kind and convert
    execer = builtins.__xonsh_execer__
    filename = macroname + "(" + name + ")"
    if kind is AST:
        ctx = set(dir(builtins)) | set(glbs.keys())
        if locs is not None:
            ctx |= set(locs.keys())
        mode = mode or "eval"
        arg = execer.parse(raw_arg, ctx, mode=mode, filename=filename)
    elif kind is types.CodeType or kind is compile:  # NOQA
        mode = mode or "eval"
        arg = execer.compile(
            raw_arg, mode=mode, glbs=glbs, locs=locs, filename=filename
        )
    elif kind is eval:
        arg = execer.eval(raw_arg, glbs=glbs, locs=locs, filename=filename)
    elif kind is exec:
        mode = mode or "exec"
        if not raw_arg.endswith("\n"):
            raw_arg += "\n"
        arg = execer.exec(raw_arg, mode=mode, glbs=glbs, locs=locs, filename=filename)
    elif kind is type:
        arg = type(execer.eval(raw_arg, glbs=glbs, locs=locs, filename=filename))
    else:
        msg = "kind={0!r} and mode={1!r} was not recongnized for macro argument {2!r}"
        raise TypeError(msg.format(kind, mode, name))
    return arg