<commit_before>local Misc    = require 'packagemanager/misc'
local Version = require 'packagemanager/version'
local PackageDB = require 'packagemanager/packagedb'


-- Requirement:
-- {
--     packageName = ...,
--     versionRange = ...,
-- }


local Dependency = {}

local function CopyContext( ctx )
    return
    {
        db = ctx.db,
        selectedPackages = Misc.copyTable(ctx.selectedPackages),
        openRequirements = Misc.copyTable(ctx.openRequirements),
        closedRequirements = Misc.copyTable(ctx.closedRequirements)
    }
end

local function SortRequirements( requirements )
    -- TODO
end

local function GetAvailablePackages( ctx, requirement )
    local selectedPackage = ctx.selectedPackages[requirement.packageName]
    if selectedPackage then
        -- we already selected a package so we can't pick a different
        return {selectedPackage}
    else
        -- we didn't select a package yet so all packages are possible
        local packageVersions =
            PackageDB.gatherPackages(ctx.db, { name = requirement.packageName })
        if not packageVersions then
            error(string.format('No package statisfies requirement: %s %s', requirement.packageName, requirement.versionRange))
        end
        local packages = {}
        for _, package in pairs(packageVersions) do
            table.insert(packages, package)
        end
        if #packages == 0 then
            error(string.format('Package %s is empty.', requirement.packageName)) -- This should not happen.
        end
        return packages
    end
end
<commit_msg>Fixed error message generated by dependency resolution<commit_after>local Misc    = require 'packagemanager/misc'
local Version = require 'packagemanager/version'
local PackageDB = require 'packagemanager/packagedb'


-- Requirement:
-- {
--     packageName = ...,
--     versionRange = ...,
-- }


local Dependency = {}

local function CopyContext( ctx )
    return
    {
        db = ctx.db,
        selectedPackages = Misc.copyTable(ctx.selectedPackages),
        openRequirements = Misc.copyTable(ctx.openRequirements),
        closedRequirements = Misc.copyTable(ctx.closedRequirements)
    }
end

local function SortRequirements( requirements )
    -- TODO
end

local function GetAvailablePackages( ctx, requirement )
    local selectedPackage = ctx.selectedPackages[requirement.packageName]
    if selectedPackage then
        -- we already selected a package, so we can't pick a different
        return {selectedPackage}
    else
        -- we didn't select a package yet, so all packages are possible
        local packages =
            PackageDB.gatherPackages(ctx.db, { name = requirement.packageName })
        if not packages or #packages == 0 then
            error(string.format('No package statisfies requirement: %s %s', requirement.packageName, requirement.versionRange))
        end
        return packages
    end
end

{'fraction_non_alphanumeric': 0.08558712769599452, 'fraction_numerical': 0.0006846970215679561, 'mean_word_length': 2.78988326848249, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900216', 'n_tokens_mistral': 772, 'n_tokens_neox': 755, 'n_words': 223}