# Buggy code
def match_to_original_specs(str_specs, specs_for_prefix):
    matches_any_spec = lambda dst: next(spc for spc in str_specs if spc.startswith(dst))
    matched_specs_for_prefix = []
    for prefix_with_dists in specs_for_prefix:
        linked = linked_data(prefix_with_dists.prefix)
        r = prefix_with_dists.r
        new_matches = []
        for spec in prefix_with_dists.specs:
            matched = matches_any_spec(spec)
            if matched:
                new_matches.append(matched)
        add_defaults_to_specs(r, linked, new_matches, prefix=prefix_with_dists.prefix)
        matched_specs_for_prefix.append(
            SpecsForPrefix(
                prefix=prefix_with_dists.prefix,
                r=prefix_with_dists.r,
                specs=new_matches,
            )
        )
    return matched_specs_for_prefix


# Traceback (KeyError)
$ conda info -a
Current conda install:

platform : linux-64
conda version : 4.3.13
conda is private : False
conda-env version : 4.3.13
conda-build version : 2.0.2
python version : 2.7.12.final.0
requests version : 2.13.0
root environment : /home/hp/bin/anaconda2  (writable)
default environment : /home/hp/bin/anaconda2/envs/kapsel
envs directories : /home/hp/bin/anaconda2/envs
/home/hp/.conda/envs
package cache : /home/hp/bin/anaconda2/pkgs
/home/hp/.conda/pkgs
channel URLs : https://repo.continuum.io/pkgs/free/linux-64
https://repo.continuum.io/pkgs/free/noarch
https://repo.continuum.io/pkgs/r/linux-64
https://repo.continuum.io/pkgs/r/noarch
https://repo.continuum.io/pkgs/pro/linux-64
https://repo.continuum.io/pkgs/pro/noarch
https://conda.anaconda.org/t/<TOKEN>/binstar/linux-64
https://conda.anaconda.org/t/<TOKEN>/binstar/noarch
config file : /home/hp/.condarc
offline mode : False
user-agent : conda/4.3.13 requests/2.13.0 CPython/2.7.12 Linux/4.9.12-100.fc24.x86_64 Fedora/24 glibc/2.23
UID:GID : 1000:1000

# conda environments:
#
anaconda-platform        /home/hp/bin/anaconda2/envs/anaconda-platform
kapsel                *  /home/hp/bin/anaconda2/envs/kapsel
kapsel-canary            /home/hp/bin/anaconda2/envs/kapsel-canary
py2                      /home/hp/bin/anaconda2/envs/py2
testing                  /home/hp/bin/anaconda2/envs/testing
root                     /home/hp/bin/anaconda2

sys.version: 2.7.12 |Anaconda 4.2.0 (64-bit)| (defaul...
sys.prefix: /home/hp/bin/anaconda2
sys.executable: /home/hp/bin/anaconda2/bin/python
conda location: /home/hp/bin/anaconda2/lib/python2.7/site-packages/conda
conda-build: /home/hp/bin/anaconda2/bin/conda-build
conda-convert: /home/hp/bin/anaconda2/bin/conda-convert
conda-develop: /home/hp/bin/anaconda2/bin/conda-develop
conda-env: /home/hp/bin/anaconda2/bin/conda-env
conda-index: /home/hp/bin/anaconda2/bin/conda-index
conda-inspect: /home/hp/bin/anaconda2/bin/conda-inspect
conda-kapsel: /home/hp/bin/anaconda2/envs/kapsel/bin/conda-kapsel
conda-metapackage: /home/hp/bin/anaconda2/bin/conda-metapackage
conda-render: /home/hp/bin/anaconda2/bin/conda-render
conda-server: /home/hp/bin/anaconda2/envs/kapsel/bin/conda-server
conda-sign: /home/hp/bin/anaconda2/bin/conda-sign
conda-skeleton: /home/hp/bin/anaconda2/bin/conda-skeleton
user site dirs:

CIO_TEST: <not set>
CONDA_DEFAULT_ENV: kapsel
CONDA_ENVS_PATH: <not set>
LD_LIBRARY_PATH: <not set>
PATH: /home/hp/bin/anaconda2/envs/kapsel/bin:/home/hp/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
PYTHONHOME: <not set>
PYTHONPATH: <not set>

License directories:
/home/hp/.continuum
/home/hp/bin/anaconda2/licenses
License files (license*.txt):
/home/hp/.continuum/license_anaconda_repo_20161003210957.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160804160500.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160727174434.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728092403.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160830123618.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160803091557.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160830104354.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo.txt
Reading license file : 6
Signature valid : 6
Vendor match : 3
product : u'mkl-optimizations'
packages : u'mkl'
end_date : u'2017-05-24'
type : u'Trial'
product : u'iopro'
packages : u'iopro'
end_date : u'2017-05-24'
type : u'Trial'
product : u'accelerate'
packages : u'numbapro mkl'
end_date : u'2017-05-24'
type : u'Trial'
/home/hp/.continuum/license_anaconda_repo_20160823133054.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160927143648.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160803113033.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728095857.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728094900.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160830104619.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728093131.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20161003210908.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
/home/hp/.continuum/license_anaconda_repo_20160728094321.txt
Reading license file : 1
Error: no signature in license: {u'license': u'test'}
Signature valid : 0
Vendor match : 0
Package/feature end dates:
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

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



`$ /home/hp/bin/anaconda2/envs/kapsel/bin/conda info -a`




Traceback (most recent call last):
File "/home/hp/bin/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 591, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/home/hp/bin/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 134, in _main
exit_code = args.func(args, p)
File "/home/hp/bin/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 324, in execute
show_info()
File "_license.pyx", line 363, in _license.show_info (_license.c:10610)
File "_license.pyx", line 310, in _license.get_end_dates (_license.c:9015)
File "_license.pyx", line 166, in _license.filter_vendor (_license.c:6214)
KeyError: 'vendor'

$ conda --version
conda 4.3.13

# Fixed code
def match_to_original_specs(specs, specs_for_prefix):
    matches_any_spec = lambda dst: next(spc for spc in specs if spc.name == dst)
    matched_specs_for_prefix = []
    for prefix_with_dists in specs_for_prefix:
        linked = linked_data(prefix_with_dists.prefix)
        r = prefix_with_dists.r
        new_matches = []
        for spec in prefix_with_dists.specs:
            matched = matches_any_spec(spec)
            if matched:
                new_matches.append(matched)
        add_defaults_to_specs(r, linked, new_matches, prefix=prefix_with_dists.prefix)
        matched_specs_for_prefix.append(
            SpecsForPrefix(
                prefix=prefix_with_dists.prefix,
                r=prefix_with_dists.r,
                specs=new_matches,
            )
        )
    return matched_specs_for_prefix