aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-02-11 13:15:00 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-02-11 13:15:00 +0300
commit7a27096e5e1231cb49aedd045aa7a5f06c656cbe (patch)
tree1901072c09390ef8f5d35ceed64a1709c9c71383 /src
parent864d1ae0a3dfbfa22fc14927a893885be870c1e2 (diff)
parentd03b2c83b7d1673b41068bbc523b35fb4192ae64 (diff)
downloadluarocks-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
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/upload/api.lua21
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...
108local function require_json() 108local 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
116end 125end
117 126
118local function redact_api_url(url) 127local function redact_api_url(url)
@@ -126,12 +135,12 @@ if not ltn12_ok then -- If not using LuaSocket and/or LuaSec...
126function Api:request(url, params, post_params) 135function 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
193function Api:request(url, params, post_params) 202function 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"