diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2016-01-10 21:09:30 -0800 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2016-01-10 21:09:30 -0800 |
commit | 2f183bcd1a596748b4f117d9f07f31a006e3b8bb (patch) | |
tree | 29eaf68fe2c61c73569c39fded45829bf0de4a64 /src | |
parent | bc758f8577a7a44e43fe047aa2e6ce019c3045de (diff) | |
download | luarocks-2f183bcd1a596748b4f117d9f07f31a006e3b8bb.tar.gz luarocks-2f183bcd1a596748b4f117d9f07f31a006e3b8bb.tar.bz2 luarocks-2f183bcd1a596748b4f117d9f07f31a006e3b8bb.zip |
provide a better error message for missing json libraries
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/upload/api.lua | 15 |
1 files 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 | |||
106 | 106 | ||
107 | -- An ode to the multitude of JSON libraries out there... | 107 | -- An ode to the multitude of JSON libraries out there... |
108 | local function require_json() | 108 | local function require_json() |
109 | for _, lib in ipairs({ "cjson", "dkjson", "json" }) do | 109 | local list = { "cjson", "dkjson", "json" } |
110 | for _, lib in ipairs(list) do | ||
110 | local json_ok, json = pcall(require, lib) | 111 | local json_ok, json = pcall(require, lib) |
111 | if json_ok then | 112 | if json_ok then |
112 | return json_ok, json | 113 | return json_ok, json |
113 | end | 114 | end |
114 | end | 115 | end |
115 | return nil | 116 | local errmsg = "Failed loading " |
117 | for i, name in ipairs(list) do | ||
118 | if i == #list then | ||
119 | errmsg = errmsg .."and '"..name.."'. Use 'luarocks search <partial-name>' to search for a library and 'luarocks install <name>' to install one." | ||
120 | else | ||
121 | errmsg = errmsg .."'"..name.."', " | ||
122 | end | ||
123 | end | ||
124 | return nil, errmsg | ||
116 | end | 125 | end |
117 | 126 | ||
118 | local function redact_api_url(url) | 127 | local function redact_api_url(url) |
@@ -126,7 +135,7 @@ if not ltn12_ok then -- If not using LuaSocket and/or LuaSec... | |||
126 | function Api:request(url, params, post_params) | 135 | function Api:request(url, params, post_params) |
127 | local vars = cfg.variables | 136 | local vars = cfg.variables |
128 | local json_ok, json = require_json() | 137 | local json_ok, json = require_json() |
129 | if not json_ok then return nil, "A JSON library is required for this command." end | 138 | if not json_ok then return nil, "A JSON library is required for this command. "..json end |
130 | 139 | ||
131 | if cfg.downloader == "wget" then | 140 | if cfg.downloader == "wget" then |
132 | local curl_ok = fs.execute_quiet(vars.CURL, "--version") | 141 | local curl_ok = fs.execute_quiet(vars.CURL, "--version") |