# Buggy code
def main(argv=None):
    """Main entry point for xonsh cli."""
    args = premain(argv)
    env = builtins.__xonsh_env__
    shell = builtins.__xonsh_shell__
    if args.mode == XonshMode.single_command:
        # run a single command and exit
        run_code_with_cache(args.command, shell.execer, mode="single")
    elif args.mode == XonshMode.script_from_file:
        # run a script contained in a file
        if os.path.isfile(args.file):
            sys.argv = args.args
            env["ARGS"] = [args.file] + args.args
            run_script_with_cache(
                args.file, shell.execer, glb=shell.ctx, loc=None, mode="exec"
            )
        else:
            print("xonsh: {0}: No such file or directory.".format(args.file))
    elif args.mode == XonshMode.script_from_stdin:
        # run a script given on stdin
        code = sys.stdin.read()
        run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None, mode="exec")
    else:
        # otherwise, enter the shell
        env["XONSH_INTERACTIVE"] = True
        ignore_sigtstp()
        if (
            env["XONSH_INTERACTIVE"]
            and not env["LOADED_CONFIG"]
            and not any(os.path.isfile(i) for i in env["XONSHRC"])
        ):
            print("Could not find xonsh configuration or run control files.")
            from xonsh import xonfig  # lazy import

            xonfig.main(["wizard", "--confirm"])
        shell.cmdloop()
    postmain(args)


# Traceback (SyntaxError)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/xonsh/execer.py", line 139, in _parse_ctx_free
debug_level=(self.debug_level > 1))
File "/usr/local/lib/python3.6/site-packages/xonsh/parsers/base.py", line 288, in parse
tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
File "/usr/local/lib/python3.6/site-packages/xonsh/ply/yacc.py", line 325, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/usr/local/lib/python3.6/site-packages/xonsh/ply/yacc.py", line 1175, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/usr/local/lib/python3.6/site-packages/xonsh/ply/yacc.py", line 187, in call_errorfunc
r = errorfunc(token)
File "/usr/local/lib/python3.6/site-packages/xonsh/parsers/base.py", line 2314, in p_error
column=p.lexpos))
File "/usr/local/lib/python3.6/site-packages/xonsh/parsers/base.py", line 383, in _parse_error
raise err
SyntaxError: 3b12ea2767bb2cf243443f97cddcbbf9:1:0: ('code:  ',)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/xonsh", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/xonsh/main.py", line 233, in main
run_code_with_cache(args.command, shell.execer, mode='single')
File "/usr/local/lib/python3.6/site-packages/xonsh/codecache.py", line 180, in run_code_with_cache
ccode = compile_code(filename, code, execer, glb, loc, mode)
File "/usr/local/lib/python3.6/site-packages/xonsh/codecache.py", line 96, in compile_code
ccode = execer.compile(code, glbs=glb, locs=loc, mode=mode)
File "/usr/local/lib/python3.6/site-packages/xonsh/execer.py", line 96, in compile
tree = self.parse(input, ctx, mode=mode)
File "/usr/local/lib/python3.6/site-packages/xonsh/execer.py", line 71, in parse
tree, input = self._parse_ctx_free(input, mode=mode)
File "/usr/local/lib/python3.6/site-packages/xonsh/execer.py", line 197, in _parse_ctx_free
raise original_error
File "/usr/local/lib/python3.6/site-packages/xonsh/execer.py", line 139, in _parse_ctx_free
debug_level=(self.debug_level > 1))
File "/usr/local/lib/python3.6/site-packages/xonsh/parsers/base.py", line 288, in parse
tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
File "/usr/local/lib/python3.6/site-packages/xonsh/ply/yacc.py", line 325, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/usr/local/lib/python3.6/site-packages/xonsh/ply/yacc.py", line 1175, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "/usr/local/lib/python3.6/site-packages/xonsh/ply/yacc.py", line 187, in call_errorfunc
r = errorfunc(token)
File "/usr/local/lib/python3.6/site-packages/xonsh/parsers/base.py", line 2314, in p_error
column=p.lexpos))
File "/usr/local/lib/python3.6/site-packages/xonsh/parsers/base.py", line 383, in _parse_error
raise err
SyntaxError: 3b12ea2767bb2cf243443f97cddcbbf9:1:0: ('code:  ',)

# Fixed code
def main(argv=None):
    """Main entry point for xonsh cli."""
    args = premain(argv)
    env = builtins.__xonsh_env__
    shell = builtins.__xonsh_shell__
    if args.mode == XonshMode.single_command:
        # run a single command and exit
        run_code_with_cache(args.command.lstrip(), shell.execer, mode="single")
    elif args.mode == XonshMode.script_from_file:
        # run a script contained in a file
        if os.path.isfile(args.file):
            sys.argv = args.args
            env["ARGS"] = [args.file] + args.args
            run_script_with_cache(
                args.file, shell.execer, glb=shell.ctx, loc=None, mode="exec"
            )
        else:
            print("xonsh: {0}: No such file or directory.".format(args.file))
    elif args.mode == XonshMode.script_from_stdin:
        # run a script given on stdin
        code = sys.stdin.read()
        run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None, mode="exec")
    else:
        # otherwise, enter the shell
        env["XONSH_INTERACTIVE"] = True
        ignore_sigtstp()
        if (
            env["XONSH_INTERACTIVE"]
            and not env["LOADED_CONFIG"]
            and not any(os.path.isfile(i) for i in env["XONSHRC"])
        ):
            print("Could not find xonsh configuration or run control files.")
            from xonsh import xonfig  # lazy import

            xonfig.main(["wizard", "--confirm"])
        shell.cmdloop()
    postmain(args)