# Buggy code
def create_file_link_actions(
    cls, transaction_context, package_info, target_prefix, requested_link_type
):
    def get_prefix_replace(source_path_data):
        if source_path_data.path_type == PathType.softlink:
            link_type = LinkType.copy
            prefix_placehoder, file_mode = "", None
        elif source_path_data.prefix_placeholder:
            link_type = LinkType.copy
            prefix_placehoder = source_path_data.prefix_placeholder
            file_mode = source_path_data.file_mode
        elif source_path_data.no_link:
            link_type = LinkType.copy
            prefix_placehoder, file_mode = "", None
        else:
            link_type = requested_link_type
            prefix_placehoder, file_mode = "", None

        return link_type, prefix_placehoder, file_mode

    def make_file_link_action(source_path_data):
        # TODO: this inner function is still kind of a mess
        noarch = package_info.repodata_record.noarch
        if noarch == NoarchType.python:
            sp_dir = transaction_context["target_site_packages_short_path"]
            target_short_path = get_python_noarch_target_path(
                source_path_data.path, sp_dir
            )
        elif noarch is None or noarch == NoarchType.generic:
            target_short_path = source_path_data.path
        else:
            raise CondaUpgradeError(
                dals("""
                The current version of conda is too old to install this package.
                Please update conda.""")
            )

        link_type, placeholder, fmode = get_prefix_replace(source_path_data)

        if placeholder:
            return PrefixReplaceLinkAction(
                transaction_context,
                package_info,
                package_info.extracted_package_dir,
                source_path_data.path,
                target_prefix,
                target_short_path,
                requested_link_type,
                placeholder,
                fmode,
                source_path_data,
            )
        else:
            return LinkPathAction(
                transaction_context,
                package_info,
                package_info.extracted_package_dir,
                source_path_data.path,
                target_prefix,
                target_short_path,
                link_type,
                source_path_data,
            )

    return tuple(make_file_link_action(spi) for spi in package_info.paths_data.paths)


# Traceback (TypeError)
conda install ../conda/bokeh-0.12.7dev3-py_0-noarch.tar.bz2 -p /Users/hsparra/milestone1_py36An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

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


Current conda install:

platform : osx-64
conda version : 4.3.21
conda is private : False
conda-env version : 4.3.21
conda-build version : 2.1.15
python version : 3.5.2.final.0
requests version : 2.12.4
root environment : /Users/hsparra/anaconda  (writable)
default environment : /Users/hsparra/milestone1_py36
envs directories : /Users/hsparra/anaconda/envs
/Users/hsparra/.conda/envs
package cache : /Users/hsparra/anaconda/pkgs
/Users/hsparra/.conda/pkgs
channel URLs : https://conda.anaconda.org/bokeh/c/dev/osx-64
https://conda.anaconda.org/bokeh/c/dev/noarch
https://conda.anaconda.org/anaconda/osx-64
https://conda.anaconda.org/anaconda/noarch
https://repo.continuum.io/pkgs/free/osx-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/osx-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/osx-64
https://repo.continuum.io/pkgs/pro/noarch
https://conda.anaconda.org/conda-forge/osx-64
https://conda.anaconda.org/conda-forge/noarch
https://conda.anaconda.org/anaconda-fusion/osx-64
https://conda.anaconda.org/anaconda-fusion/noarch
https://conda.anaconda.org/anaconda-mosaic/osx-64
https://conda.anaconda.org/anaconda-mosaic/noarch
https://conda.anaconda.org/quanyuan/osx-64
https://conda.anaconda.org/quanyuan/noarch
config file : /Users/hsparra/.condarc
netrc file : None
offline mode : False
user-agent : conda/4.3.21 requests/2.12.4 CPython/3.5.2 Darwin/16.6.0 OSX/10.12.5
UID:GID : 503:20

$ /Users/hsparra/milestone1_py36/bin/conda install ../conda/bokeh-0.12.7dev3-py_0-noarch.tar.bz2 -p /Users/hsparra/milestone1_py36`




Traceback (most recent call last):
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/exceptions.py", line 632, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/cli/main.py", line 137, in _main
exit_code = args.func(args, p)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/cli/main_install.py", line 80, in execute
install(args, parser, 'install')
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/cli/install.py", line 199, in install
explicit(args_packages, prefix, verbose=not context.quiet)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/misc.py", line 110, in explicit
execute_actions(actions, index, verbose=verbose)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/plan.py", line 830, in execute_actions
execute_instructions(plan, index, verbose)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/instructions.py", line 247, in execute_instructions
cmd(state, arg)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/instructions.py", line 108, in UNLINKLINKTRANSACTION_CMD
txn.execute()
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/link.py", line 263, in execute
self.verify()
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/link.py", line 242, in verify
self.prepare()
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/link.py", line 173, in prepare
concatv(unlink_actions, link_actions))
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/link.py", line 172, in <genexpr>
self.all_actions = tuple(per_pkg_actions for per_pkg_actions in
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/link.py", line 169, in <genexpr>
for pkg_info, lt in zip(self.packages_info_to_link, link_types)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/link.py", line 406, in make_link_actions
file_link_actions = LinkPathAction.create_file_link_actions(*required_quad)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/path_actions.py", line 181, in create_file_link_actions
return tuple(make_file_link_action(spi) for spi in package_info.paths_data.paths)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/path_actions.py", line 181, in <genexpr>
return tuple(make_file_link_action(spi) for spi in package_info.paths_data.paths)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/core/path_actions.py", line 161, in make_file_link_action
target_short_path = get_python_noarch_target_path(source_path_info.path, sp_dir)
File "/Users/hsparra/anaconda/lib/python3.5/site-packages/conda/common/path.py", line 238, in get_python_noarch_target_path
return source_short_path.replace('site-packages', sp_dir, 1)
TypeError: Can't convert 'NoneType' object to str implicitly`

# Fixed code
def create_file_link_actions(
    cls, transaction_context, package_info, target_prefix, requested_link_type
):
    def get_prefix_replace(source_path_data):
        if source_path_data.path_type == PathType.softlink:
            link_type = LinkType.copy
            prefix_placehoder, file_mode = "", None
        elif source_path_data.prefix_placeholder:
            link_type = LinkType.copy
            prefix_placehoder = source_path_data.prefix_placeholder
            file_mode = source_path_data.file_mode
        elif source_path_data.no_link:
            link_type = LinkType.copy
            prefix_placehoder, file_mode = "", None
        else:
            link_type = requested_link_type
            prefix_placehoder, file_mode = "", None

        return link_type, prefix_placehoder, file_mode

    def make_file_link_action(source_path_data):
        # TODO: this inner function is still kind of a mess
        noarch = package_info.repodata_record.noarch
        if noarch == NoarchType.python:
            sp_dir = transaction_context["target_site_packages_short_path"]
            if sp_dir is None:
                raise CondaError(
                    "Unable to determine python site-packages "
                    "dir in target_prefix!\nPlease make sure "
                    "python is installed in %s" % target_prefix
                )
            target_short_path = get_python_noarch_target_path(
                source_path_data.path, sp_dir
            )
        elif noarch is None or noarch == NoarchType.generic:
            target_short_path = source_path_data.path
        else:
            raise CondaUpgradeError(
                dals("""
                The current version of conda is too old to install this package.
                Please update conda.""")
            )

        link_type, placeholder, fmode = get_prefix_replace(source_path_data)

        if placeholder:
            return PrefixReplaceLinkAction(
                transaction_context,
                package_info,
                package_info.extracted_package_dir,
                source_path_data.path,
                target_prefix,
                target_short_path,
                requested_link_type,
                placeholder,
                fmode,
                source_path_data,
            )
        else:
            return LinkPathAction(
                transaction_context,
                package_info,
                package_info.extracted_package_dir,
                source_path_data.path,
                target_prefix,
                target_short_path,
                link_type,
                source_path_data,
            )

    return tuple(make_file_link_action(spi) for spi in package_info.paths_data.paths)