aboutsummaryrefslogtreecommitdiffstats
path: root/tools/migration
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2011-04-05 12:59:24 +0100
committerMatthew Wild <mwild1@gmail.com>2011-04-05 12:59:24 +0100
commit0e4599d1b5f5adec0105017c7fd0b63d63a132da (patch)
treed13bd97331a195a6c78ead441e3a06268b1ac41f /tools/migration
parentcef7f598c03ede6a08a39720c861047d7ebf904d (diff)
downloadprosody-0e4599d1b5f5adec0105017c7fd0b63d63a132da.tar.gz
prosody-0e4599d1b5f5adec0105017c7fd0b63d63a132da.zip
tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Diffstat (limited to 'tools/migration')
-rw-r--r--tools/migration/prosody-migrator.lua35
1 files changed, 22 insertions, 13 deletions
diff --git a/tools/migration/prosody-migrator.lua b/tools/migration/prosody-migrator.lua
index 82eeab9d..20631fb1 100644
--- a/tools/migration/prosody-migrator.lua
+++ b/tools/migration/prosody-migrator.lua
@@ -71,21 +71,30 @@ if not config[to_store] then
have_err = true;
print("Error: Output store '"..to_store.."' not found in the config file.");
end
-if not config[from_store].type then
- have_err = true;
- print("Error: Input store type not specified in the config file");
-elseif not pcall(require, "migrator."..config[from_store].type) then
- have_err = true;
- print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type);
-end
-if not config[to_store].type then
- have_err = true;
- print("Error: Output store type not specified in the config file");
-elseif not pcall(require, "migrator."..config[to_store].type) then
- have_err = true;
- print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type);
+
+function load_store_handler(name)
+ local store_type = config[name].type;
+ if not store_type then
+ print("Error: "..name.." store type not specified in the config file");
+ return false;
+ else
+ local ok, err = pcall(require, "migrator."..store_type);
+ if not ok then
+ if package.loaded["migrator."..store_type] then
+ print(("Error: Failed to initialize '%s' store:\n\t%s")
+ :format(name, err));
+ else
+ print(("Error: Unrecognised store type for '%s': %s")
+ :format(from_store, store_type));
+ end
+ return false;
+ end
+ end
+ return true;
end
+have_err = have_err or not(load_store_handler(from_store, "input") and load_store_handler(to_store, "output"));
+
if have_err then
print("");
print("Usage: "..arg[0].." FROM_STORE TO_STORE");