Software /
code /
prosody
Diff
tools/migration/prosody-migrator.lua @ 4235:899ffc1674b5
tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 05 Apr 2011 12:59:24 +0100 |
parent | 4229:f15b4e9ba688 |
child | 4239:69fe5fd861e7 |
line wrap: on
line diff
--- a/tools/migration/prosody-migrator.lua Tue Apr 05 12:58:14 2011 +0100 +++ b/tools/migration/prosody-migrator.lua Tue Apr 05 12:59:24 2011 +0100 @@ -71,20 +71,29 @@ 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); + +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 -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); -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("");