# Buggy code
def main():
    from conda.base.constants import ROOT_ENV_NAME
    from conda.utils import shells

    if "-h" in sys.argv or "--help" in sys.argv:
        # all execution paths sys.exit at end.
        help(sys.argv[1], sys.argv[2])

    if len(sys.argv) > 2:
        shell = sys.argv[2]
        shelldict = shells[shell]
    else:
        shelldict = {}

    if sys.argv[1] == "..activate":
        print(get_activate_path(shelldict))
        sys.exit(0)

    elif sys.argv[1] == "..deactivate.path":
        import re

        activation_path = get_activate_path(shelldict)

        if os.getenv("_CONDA_HOLD"):
            new_path = re.sub(
                r"%s(:?)" % re.escape(activation_path),
                r"CONDA_PATH_PLACEHOLDER\1",
                os.environ[str("PATH")],
                1,
            )
        else:
            new_path = re.sub(
                r"%s(:?)" % re.escape(activation_path), r"", os.environ[str("PATH")], 1
            )

        print(new_path)
        sys.exit(0)

    elif sys.argv[1] == "..checkenv":
        if len(sys.argv) < 4:
            raise ArgumentError(
                "Invalid arguments to checkenv.  Need shell and env name/path"
            )
        if len(sys.argv) > 4:
            raise ArgumentError("did not expect more than one argument.")
        if sys.argv[3].lower() == ROOT_ENV_NAME.lower():
            # no need to check root env and try to install a symlink there
            sys.exit(0)
            # raise CondaSystemExit

        # this should throw an error and exit if the env or path can't be found.
        try:
            prefix = prefix_from_arg(sys.argv[3], shelldict=shelldict)
        except ValueError as e:
            raise CondaValueError(text_type(e))

        # Make sure an env always has the conda symlink
        try:
            from conda.base.context import context
            import conda.install

            conda.install.symlink_conda(prefix, context.root_prefix, shell)
        except (IOError, OSError) as e:
            if e.errno == errno.EPERM or e.errno == errno.EACCES:
                msg = (
                    "Cannot activate environment {0}.\n"
                    "User does not have write access for conda symlinks.".format(
                        sys.argv[2]
                    )
                )
                raise CondaEnvironmentError(msg)
            raise
        sys.exit(0)
        # raise CondaSystemExit
    elif sys.argv[1] == "..changeps1":
        from conda.base.context import context

        path = int(context.changeps1)

    else:
        # This means there is a bug in main.py
        raise CondaValueError("unexpected command")

    # This print is actually what sets the PATH or PROMPT variable.  The shell
    # script gets this value, and finishes the job.
    print(path)


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def main():
    from ..base.constants import ROOT_ENV_NAME
    from ..utils import shells

    if "-h" in sys.argv or "--help" in sys.argv:
        # all execution paths sys.exit at end.
        help(sys.argv[1], sys.argv[2])

    if len(sys.argv) > 2:
        shell = sys.argv[2]
        shelldict = shells[shell]
    else:
        shelldict = {}

    if sys.argv[1] == "..activate":
        print(get_activate_path(shelldict))
        sys.exit(0)

    elif sys.argv[1] == "..deactivate.path":
        import re

        activation_path = get_activate_path(shelldict)

        if os.getenv("_CONDA_HOLD"):
            new_path = re.sub(
                r"%s(:?)" % re.escape(activation_path),
                r"CONDA_PATH_PLACEHOLDER\1",
                os.environ[str("PATH")],
                1,
            )
        else:
            new_path = re.sub(
                r"%s(:?)" % re.escape(activation_path), r"", os.environ[str("PATH")], 1
            )

        print(new_path)
        sys.exit(0)

    elif sys.argv[1] == "..checkenv":
        if len(sys.argv) < 4:
            raise ArgumentError(
                "Invalid arguments to checkenv.  Need shell and env name/path"
            )
        if len(sys.argv) > 4:
            raise ArgumentError("did not expect more than one argument.")
        if sys.argv[3].lower() == ROOT_ENV_NAME.lower():
            # no need to check root env and try to install a symlink there
            sys.exit(0)
            # raise CondaSystemExit

        # this should throw an error and exit if the env or path can't be found.
        try:
            prefix = prefix_from_arg(sys.argv[3], shelldict=shelldict)
        except ValueError as e:
            raise CondaValueError(text_type(e))

        # Make sure an env always has the conda symlink
        try:
            from ..base.context import context
            from ..install import symlink_conda

            symlink_conda(prefix, context.root_prefix, shell)
        except (IOError, OSError) as e:
            if e.errno == errno.EPERM or e.errno == errno.EACCES:
                msg = (
                    "Cannot activate environment {0}.\n"
                    "User does not have write access for conda symlinks.".format(
                        sys.argv[2]
                    )
                )
                raise CondaEnvironmentError(msg)
            raise
        sys.exit(0)
        # raise CondaSystemExit
    elif sys.argv[1] == "..changeps1":
        from ..base.context import context

        path = int(context.changeps1)

    else:
        # This means there is a bug in main.py
        raise CondaValueError("unexpected command")

    # This print is actually what sets the PATH or PROMPT variable.  The shell
    # script gets this value, and finishes the job.
    print(path)