# Buggy code
def fork_shell(env, shellcmd, cwd):
    or_ctrld = "" if windows else "or 'Ctrl+D' "
    err(
        "Launching subshell in virtual environment. Type 'exit' ",
        or_ctrld,
        "to return.",
        sep="",
    )
    if "VIRTUAL_ENV" in os.environ:
        err(
            "Be aware that this environment will be nested on top "
            "of '%s'" % Path(os.environ["VIRTUAL_ENV"]).name
        )
    inve(env, *shellcmd, cwd=cwd)


# Traceback (AttributeError)
λ exit
Traceback (most recent call last):
File "c:\tools\anaconda3\lib\site-packages\pipenv\core.py", line 2107, in do_shell
c = pexpect.spawn(
AttributeError: module 'pexpect' has no attribute 'spawn'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\tools\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\tools\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\tools\Anaconda3\Scripts\pipenv.exe\__main__.py", line 9, in <module>
File "c:\tools\anaconda3\lib\site-packages\pipenv\vendor\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\tools\anaconda3\lib\site-packages\pipenv\vendor\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\tools\anaconda3\lib\site-packages\pipenv\vendor\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\tools\anaconda3\lib\site-packages\pipenv\vendor\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\tools\anaconda3\lib\site-packages\pipenv\vendor\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\tools\anaconda3\lib\site-packages\pipenv\cli.py", line 281, in shell
core.do_shell(three=three, python=python, fancy=fancy, shell_args=shell_args)
File "c:\tools\anaconda3\lib\site-packages\pipenv\core.py", line 2123, in do_shell
pew.workon_cmd([workon_name])
File "c:\tools\anaconda3\lib\site-packages\pipenv\patched\pew\pew.py", line 368, in workon_cmd
shell(env, cwd=project_dir)
File "c:\tools\anaconda3\lib\site-packages\pipenv\patched\pew\pew.py", line 208, in shell
fork_cmder(env, cwd)
File "c:\tools\anaconda3\lib\site-packages\pipenv\patched\pew\pew.py", line 179, in fork_cmder
fork_shell(env, shell_cmd, cwd)
File "c:\tools\anaconda3\lib\site-packages\pipenv\patched\pew\pew.py", line 154, in fork_shell
inve(env, *shellcmd, cwd=cwd)
File "c:\tools\anaconda3\lib\site-packages\pipenv\patched\pew\pew.py", line 137, in inve
return check_call([command] + list(args), shell=windows, **kwargs)
File "c:\tools\anaconda3\lib\site-packages\pipenv\patched\pew\_utils.py", line 44, in call
return f([ex] + list(cmd[1:]), **kwargs)  # list-conversion is required in case `cmd` is a tuple
File "c:\tools\anaconda3\lib\subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\Windows\\system32\\cmd.EXE', '/k', '%CMDER_ROOT%\\vendor\\init.bat']' returned non-zero exit status 1.

# Fixed code
def fork_shell(env, shellcmd, cwd):
    or_ctrld = "" if windows else "or 'Ctrl+D' "
    err(
        "Launching subshell in virtual environment. Type 'exit' ",
        or_ctrld,
        "to return.",
        sep="",
    )
    if "VIRTUAL_ENV" in os.environ:
        err(
            "Be aware that this environment will be nested on top "
            "of '%s'" % Path(os.environ["VIRTUAL_ENV"]).name
        )
    try:
        inve(env, *shellcmd, cwd=cwd)
    except CalledProcessError:
        # These shells report errors when the last command executed in the
        # subshell in an error. This causes the subprocess to fail, which is
        # not what we want. Stay silent for them, there's nothing we can do.
        shell_name, _ = os.path.splitext(os.path.basename(shellcmd[0]))
        suppress_error = shell_name.tolower() in ["cmd", "powershell", "pwsh"]
        if not suppress_error:
            raise