From 833b8bbccc758049d08ef3fa8cd8cbd2a4366a91 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 17 Jun 2013 10:54:43 +0200 Subject: Added some additional error info when parsing version constraints, see issue https://github.com/Olivine-Labs/busted/issues/169 --- src/luarocks/deps.lua | 19 ++++++++++++------- src/luarocks/fetch.lua | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 6d5f3fef..93b187cf 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -170,9 +170,14 @@ local function parse_constraint(input) assert(type(input) == "string") local no_upgrade, op, version, rest = input:match("^(@?)([<>=~!]*)%s*([%w%.%_%-]+)[%s,]*(.*)") - op = operators[op] + local _op = operators[op] version = parse_version(version) - if not op or not version then return nil end + if not _op then + return nil, "Encountered bad constraint operator: '"..tostring(op).."' in '"..input.."'" + end + if not version then + return nil, "Could not parse version from constraint: '"..input.."'" + end return { op = op, version = version, no_upgrade = no_upgrade=="@" and true or nil }, rest end @@ -187,13 +192,13 @@ end function parse_constraints(input) assert(type(input) == "string") - local constraints, constraint = {}, nil + local constraints, constraint, oinput = {}, nil, input while #input > 0 do constraint, input = parse_constraint(input) if constraint then table.insert(constraints, constraint) else - return nil + return nil, "Failed to parse constraint '"..tostring(o_input).."' with error: ".. input end end return constraints @@ -213,9 +218,9 @@ function parse_dep(dep) assert(type(dep) == "string") local name, rest = dep:match("^%s*([a-zA-Z][a-zA-Z0-9%.%-%_]*)%s*(.*)") - if not name then return nil end - local constraints = parse_constraints(rest) - if not constraints then return nil end + if not name then return nil, "failed to extract dependency name from '"..tostring(dep).."'" end + local constraints, err = parse_constraints(rest) + if not constraints then return nil, err end return { name = name, constraints = constraints } end diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 3bb0cdc0..bfdbacec 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -189,9 +189,9 @@ function load_local_rockspec(filename) or base if rockspec.dependencies then for i = 1, #rockspec.dependencies do - local parsed = deps.parse_dep(rockspec.dependencies[i]) + local parsed, err = deps.parse_dep(rockspec.dependencies[i]) if not parsed then - return nil, "Parse error processing dependency '"..rockspec.dependencies[i].."'" + return nil, "Parse error processing dependency '"..rockspec.dependencies[i].."': "..tostring(err) end rockspec.dependencies[i] = parsed end -- cgit v1.2.3-55-g6feb