From 66a4d40893199fbee5eed5abd3c91aad0a3cce2b Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 19 Oct 2016 12:43:41 -0400 Subject: Refactor error message and add extra checks. --- src/luarocks/manif.lua | 4 +++- src/luarocks/manif/writer.lua | 6 ++---- src/luarocks/pack.lua | 6 ++---- src/luarocks/repos.lua | 17 +++++++++-------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 680b5cfe..bd6fd6ee 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -25,7 +25,9 @@ function manif.load_rock_manifest(name, version, root) end local pathname = path.rock_manifest_file(name, version, root) local rock_manifest = persist.load_into_table(pathname) - if not rock_manifest then return nil end + if not rock_manifest then + return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?" + end manif.rock_manifest_cache[name_version] = rock_manifest return rock_manifest.rock_manifest end diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 75ea3b81..1eb5ee7c 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua @@ -189,10 +189,8 @@ local function store_results(results, manifest, dep_handler) local entrytable = {} entrytable.arch = entry.arch if entry.arch == "installed" then - local rock_manifest = manif.load_rock_manifest(name, version) - if not rock_manifest then - return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" - end + local rock_manifest, err = manif.load_rock_manifest(name, version) + if not rock_manifest then return nil, err end entrytable.modules = store_package_items(repos.package_modules, name, version, manifest.modules) entrytable.commands = store_package_items(repos.package_commands, name, version, manifest.commands) end diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 989d49ee..49c68e85 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -102,10 +102,8 @@ local function do_pack_binary_rock(name, version, tree) return nil, "'"..name.." "..version.."' does not seem to be an installed rock." end - local rock_manifest = manif.load_rock_manifest(name, version, root) - if not rock_manifest then - return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" - end + local rock_manifest, err = manif.load_rock_manifest(name, version, root) + if not rock_manifest then return nil, err end local name_version = name .. "-" .. version local rock_file = fs.absolute_name(name_version .. "."..cfg.arch..".rock") diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index f1d58da0..0ed9068c 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -78,6 +78,7 @@ function repos.package_modules(package, version) local result = {} local rock_manifest = manif.load_rock_manifest(package, version) + if not rock_manifest then return result end store_package_data(result, package, rock_manifest.lib) store_package_data(result, package, rock_manifest.lua) return result @@ -97,6 +98,7 @@ function repos.package_commands(package, version) local result = {} local rock_manifest = manif.load_rock_manifest(package, version) + if not rock_manifest then return result end store_package_data(result, package, rock_manifest.bin) return result end @@ -112,7 +114,7 @@ function repos.has_binaries(name, version) assert(type(version) == "string") local rock_manifest = manif.load_rock_manifest(name, version) - if rock_manifest.bin then + if rock_manifest and rock_manifest.bin then for name, md5 in pairs(rock_manifest.bin) do -- TODO verify that it is the same file. If it isn't, find the actual command. if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, name)) then @@ -196,7 +198,7 @@ function repos.deploy_files(name, version, wrap_bin_scripts) local function deploy_file_tree(file_tree, path_fn, deploy_dir, move_fn) local source_dir = path_fn(name, version) - return recurse_rock_manifest_tree(file_tree, + return recurse_rock_manifest_tree(file_tree, function(parent_path, parent_module, file) local source = dir.path(source_dir, parent_path, file) local target = dir.path(deploy_dir, parent_path, file) @@ -226,7 +228,8 @@ function repos.deploy_files(name, version, wrap_bin_scripts) ) end - local rock_manifest = manif.load_rock_manifest(name, version) + local rock_manifest, err = manif.load_rock_manifest(name, version) + if not rock_manifest then return nil, err end local ok, err = true if rock_manifest.bin then @@ -305,12 +308,10 @@ function repos.delete_version(name, version, deps_mode, quick) ) end - local rock_manifest = manif.load_rock_manifest(name, version) - if not rock_manifest then - return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" - end + local rock_manifest, err = manif.load_rock_manifest(name, version) + if not rock_manifest then return nil, err end - local ok, err = true + local ok = true if rock_manifest.bin then ok, err = delete_deployed_file_tree(rock_manifest.bin, cfg.deploy_bin_dir, cfg.wrapper_suffix) end -- cgit v1.2.3-55-g6feb