Comparison

tools/migration/migrator/prosody_files.lua @ 5974:9ce0d246c851

tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 03 Jan 2014 15:52:52 -0500
parent 5021:85b2689dbcfe
child 7881:4e3067272fae
comparison
equal deleted inserted replaced
5953:1c08d6cca552 5974:9ce0d246c851
11 local mtools = require "migrator.mtools"; 11 local mtools = require "migrator.mtools";
12 local next = next; 12 local next = next;
13 local pairs = pairs; 13 local pairs = pairs;
14 local json = require "util.json"; 14 local json = require "util.json";
15 local os_getenv = os.getenv; 15 local os_getenv = os.getenv;
16 local error = error;
16 17
17 prosody = {}; 18 prosody = {};
18 local dm = require "util.datamanager" 19 local dm = require "util.datamanager"
19 20
20 module "prosody_files" 21 module "prosody_files"
93 local iter = coroutine.wrap(function()handle_root_dir(path);end); 94 local iter = coroutine.wrap(function()handle_root_dir(path);end);
94 -- get per-user stores, sorted 95 -- get per-user stores, sorted
95 local iter = mtools.sorted { 96 local iter = mtools.sorted {
96 reader = function() 97 reader = function()
97 local x = iter(); 98 local x = iter();
98 if x then 99 while x do
99 dm.set_data_path(path); 100 dm.set_data_path(path);
100 local err; 101 local err;
101 x.data, err = dm.load(x.user, x.host, x.store); 102 x.data, err = dm.load(x.user, x.host, x.store);
102 if x.data == nil and err then 103 if x.data == nil and err then
103 error(("Error loading data at path %s for %s@%s (%s store)") 104 local p = dm.getpath(x.user, x.host, x.store);
104 :format(path, x.user or "<nil>", x.host or "<nil>", x.store or "<nil>"), 0); 105 print(("Error loading data at path %s for %s@%s (%s store): %s")
106 :format(p, x.user or "<nil>", x.host or "<nil>", x.store or "<nil>", err or "<nil>"));
107 else
108 return x;
105 end 109 end
106 return x; 110 x = iter();
107 end 111 end
108 end; 112 end;
109 sorter = function(a, b) 113 sorter = function(a, b)
110 local a_host, a_user, a_store = a.host or "", a.user or "", a.store or ""; 114 local a_host, a_user, a_store = a.host or "", a.user or "", a.store or "";
111 local b_host, b_user, b_store = b.host or "", b.user or "", b.store or ""; 115 local b_host, b_user, b_store = b.host or "", b.user or "", b.store or "";