# Buggy code
def list_packages(
    prefix, installed, regex=None, format="human", show_channel_urls=show_channel_urls
):
    res = 1

    result = []
    for dist in get_packages(installed, regex):
        res = 0
        if format == "canonical":
            result.append(dist)
            continue
        if format == "export":
            result.append("=".join(dist2quad(dist)[:3]))
            continue

        try:
            # Returns None if no meta-file found (e.g. pip install)
            info = install.is_linked(prefix, dist)
            features = set(info.get("features", "").split())
            disp = "%(name)-25s %(version)-15s %(build)15s" % info
            disp += "  %s" % common.disp_features(features)
            schannel = info.get("schannel")
            if (
                show_channel_urls
                or show_channel_urls is None
                and schannel != "defaults"
            ):
                disp += "  %s" % schannel
            result.append(disp)
        except (AttributeError, IOError, KeyError, ValueError) as e:
            log.debug(str(e))
            result.append("%-25s %-15s %15s" % dist2quad(dist, channel=False))

    return res, result


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/ilan/minonda/bin/conda", line 6, in <module>
sys.exit(main())
File "/home/ilan/conda/conda/cli/main.py", line 120, in main
args_func(args, p)
File "/home/ilan/conda/conda/cli/main.py", line 127, in args_func
args.func(args, p)
File "/home/ilan/conda/conda/cli/main_install.py", line 62, in execute
install.install(args, parser, 'install')
File "/home/ilan/conda/conda/cli/install.py", line 394, in install
plan.execute_actions(actions, index, verbose=not args.quiet)
File "/home/ilan/conda/conda/plan.py", line 555, in execute_actions
inst.execute_instructions(plan, index, verbose)
File "/home/ilan/conda/conda/instructions.py", line 133, in execute_instructions
cmd(state, arg)
File "/home/ilan/conda/conda/instructions.py", line 80, in UNLINK_CMD
install.unlink(state['prefix'], arg)
File "/home/ilan/conda/conda/install.py", line 1075, in unlink
mk_menus(prefix, meta['files'], remove=True)
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def list_packages(
    prefix, installed, regex=None, format="human", show_channel_urls=show_channel_urls
):
    res = 1

    result = []
    for dist in get_packages(installed, regex):
        res = 0
        if format == "canonical":
            result.append(dist)
            continue
        if format == "export":
            result.append("=".join(dist2quad(dist)[:3]))
            continue

        try:
            # Returns None if no meta-file found (e.g. pip install)
            info = install.is_linked(prefix, dist)
            features = set(info.get("features", "").split())
            disp = "%(name)-25s %(version)-15s %(build)15s" % info
            disp += "  %s" % common.disp_features(features)
            schannel = info.get("schannel")
            if (
                show_channel_urls
                or show_channel_urls is None
                and schannel != "defaults"
            ):
                disp += "  %s" % schannel
            result.append(disp)
        except (AttributeError, IOError, KeyError, ValueError) as e:
            log.debug(str(e))
            result.append("%-25s %-15s %s" % dist2quad(dist)[:3])

    return res, result