From 2f183bcd1a596748b4f117d9f07f31a006e3b8bb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sun, 10 Jan 2016 21:09:30 -0800 Subject: provide a better error message for missing json libraries --- src/luarocks/upload/api.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index 2cf462fb..b56f23e1 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua @@ -106,13 +106,22 @@ end -- An ode to the multitude of JSON libraries out there... local function require_json() - for _, lib in ipairs({ "cjson", "dkjson", "json" }) do + local list = { "cjson", "dkjson", "json" } + for _, lib in ipairs(list) do local json_ok, json = pcall(require, lib) if json_ok then return json_ok, json end end - return nil + local errmsg = "Failed loading " + for i, name in ipairs(list) do + if i == #list then + errmsg = errmsg .."and '"..name.."'. Use 'luarocks search ' to search for a library and 'luarocks install ' to install one." + else + errmsg = errmsg .."'"..name.."', " + end + end + return nil, errmsg end local function redact_api_url(url) @@ -126,7 +135,7 @@ if not ltn12_ok then -- If not using LuaSocket and/or LuaSec... function Api:request(url, params, post_params) local vars = cfg.variables local json_ok, json = require_json() - if not json_ok then return nil, "A JSON library is required for this command." end + if not json_ok then return nil, "A JSON library is required for this command. "..json end if cfg.downloader == "wget" then local curl_ok = fs.execute_quiet(vars.CURL, "--version") -- cgit v1.2.3-55-g6feb