diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-02-11 13:15:00 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-02-11 13:15:00 +0300 |
| commit | 7a27096e5e1231cb49aedd045aa7a5f06c656cbe (patch) | |
| tree | 1901072c09390ef8f5d35ceed64a1709c9c71383 | |
| parent | 864d1ae0a3dfbfa22fc14927a893885be870c1e2 (diff) | |
| parent | d03b2c83b7d1673b41068bbc523b35fb4192ae64 (diff) | |
| download | luarocks-7a27096e5e1231cb49aedd045aa7a5f06c656cbe.tar.gz luarocks-7a27096e5e1231cb49aedd045aa7a5f06c656cbe.tar.bz2 luarocks-7a27096e5e1231cb49aedd045aa7a5f06c656cbe.zip | |
Merge pull request #483 from Tieske/errmsg_json
provide a better error message for missing json libraries
| -rw-r--r-- | src/luarocks/upload/api.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index 2cf462fb..6df24569 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,12 +135,12 @@ 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, err = fs.is_tool_available(vars.CURL, "curl") |
| 133 | if not curl_ok then | 142 | if not curl_ok then |
| 134 | return nil, "Missing network helper program 'curl'.\nMake sure 'curl' is installed and available from your path." | 143 | return nil, err |
| 135 | end | 144 | end |
| 136 | end | 145 | end |
| 137 | 146 | ||
| @@ -192,7 +201,7 @@ local warned_luasec = false | |||
| 192 | 201 | ||
| 193 | function Api:request(url, params, post_params) | 202 | function Api:request(url, params, post_params) |
| 194 | local json_ok, json = require_json() | 203 | local json_ok, json = require_json() |
| 195 | if not json_ok then return nil, "A JSON library is required for this command." end | 204 | if not json_ok then return nil, "A JSON library is required for this command. "..json end |
| 196 | local server = tostring(self.config.server) | 205 | local server = tostring(self.config.server) |
| 197 | local http_ok, http | 206 | local http_ok, http |
| 198 | local via = "luasocket" | 207 | local via = "luasocket" |
