def find_matching_with_errors(dependency,
                                all               = false,
                                matching_platform = true,
                                prerelease        = false)
    found = {}

    rejected_specs = {}

    list(all, prerelease).each do |source_uri, specs|
      found[source_uri] = specs.select do |spec_name, version, spec_platform|
        if dependency.match?(spec_name, version)
          if matching_platform and !Gem::Platform.match(spec_platform)
            pm = (rejected_specs[dependency] ||= Gem::PlatformMismatch.new(spec_name, version))
            pm.add_platform spec_platform
            false
          else
            true
          end
        end
      end
    end

    errors = rejected_specs.values

    specs_and_sources = []

    found.each do |source_uri, specs|
      uri_str = source_uri.to_s
      specs_and_sources.concat(specs.map { |spec| [spec, uri_str] })
    end

    [specs_and_sources, errors]
  end
#
Find spec names that match +dependency+.  If +all+ is true, all
matching released versions are returned.  If +matching_platform+
is false, gems for all platforms are returned.