# Buggy code
def source_alias(args, stdin=None):
    """Executes the contents of the provided files in the current context.
    If sourced file isn't found in cwd, search for file along $PATH to source
    instead.
    """
    env = builtins.__xonsh_env__
    encoding = env.get("XONSH_ENCODING")
    errors = env.get("XONSH_ENCODING_ERRORS")
    for fname in args:
        if not os.path.isfile(fname):
            fname = locate_binary(fname)
        with open(fname, "r", encoding=encoding, errors=errors) as fp:
            builtins.execx(fp.read(), "exec", builtins.__xonsh_ctx__)


# Traceback (IndexError)
Traceback (most recent call last):
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 10323, in wrapped_simple_command
r = f(args, i)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 14407, in source_alias
builtins.execx(fp.read(), 'exec', builtins.__xonsh_ctx__)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16152, in exec
transform=transform)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16113, in compile
tree = self.parse(input, ctx, mode=mode, transform=transform)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16084, in parse
tree, input = self._parse_ctx_free(input, mode=mode)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16166, in _parse_ctx_free
debug_level=(self.debug_level > 1))
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/parsers/base.py", line 307, in parse
tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/vendor/lib/python3.5/site-packages/ply/yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/vendor/lib/python3.5/site-packages/ply/yacc.py", line 1181, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/vendor/lib/python3.5/site-packages/ply/yacc.py", line 193, in call_errorfunc
r = errorfunc(token)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/parsers/base.py", line 2340, in p_error
self.xonsh_code)
File "/usr/local/Cellar/xonsh/0.4.3/libexec/lib/python3.5/site-packages/xonsh/parsers/base.py", line 404, in _parse_error
err_line = line.splitlines()[loc.lineno - 1]
IndexError: list index out of range

# Fixed code
def source_alias(args, stdin=None):
    """Executes the contents of the provided files in the current context.
    If sourced file isn't found in cwd, search for file along $PATH to source
    instead.
    """
    env = builtins.__xonsh_env__
    encoding = env.get("XONSH_ENCODING")
    errors = env.get("XONSH_ENCODING_ERRORS")
    for fname in args:
        if not os.path.isfile(fname):
            fname = locate_binary(fname)
        with open(fname, "r", encoding=encoding, errors=errors) as fp:
            src = fp.read()
        if not src.endswith("\n"):
            src += "\n"
        builtins.execx(src, "exec", builtins.__xonsh_ctx__)