Software /
code /
prosody-modules
Comparison
mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 1726:160c35d2a5a2
mod_storage_xmlarchive: Improve logging of parse errors
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 11 May 2015 14:16:23 +0200 |
parent | 1690:8c0fbc685364 |
child | 1727:8f12afb633ec |
comparison
equal
deleted
inserted
replaced
1725:d85d5b0bf977 | 1726:160c35d2a5a2 |
---|---|
98 local items, xmlfile; | 98 local items, xmlfile; |
99 local first_item, last_item; | 99 local first_item, last_item; |
100 | 100 |
101 return function () | 101 return function () |
102 if limit and count >= limit then xmlfile:close() return; end | 102 if limit and count >= limit then xmlfile:close() return; end |
103 local filename; | |
103 | 104 |
104 for d = start_day, last_day, step do | 105 for d = start_day, last_day, step do |
105 if d ~= start_day or not items then | 106 if d ~= start_day or not items then |
106 module:log("debug", "Load items for %s", dates[d]); | 107 module:log("debug", "Load items for %s", dates[d]); |
107 start_day = d; | 108 start_day = d; |
110 first_item, last_item = 1, #items; | 111 first_item, last_item = 1, #items; |
111 else | 112 else |
112 first_item, last_item = #items, 1; | 113 first_item, last_item = #items, 1; |
113 end | 114 end |
114 local ferr; | 115 local ferr; |
115 xmlfile, ferr = io.open(dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml")); | 116 filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); |
117 xmlfile, ferr = io.open(filename); | |
116 if not xmlfile then | 118 if not xmlfile then |
117 module:log("error", "Error: %s", ferr); | 119 module:log("error", "Error: %s", ferr); |
118 return; | 120 return; |
119 end | 121 end |
120 end | 122 end |
135 | 137 |
136 xmlfile:seek("set", item.offset); | 138 xmlfile:seek("set", item.offset); |
137 local data = xmlfile:read(item.length); | 139 local data = xmlfile:read(item.length); |
138 local ok, err = stream:feed(data); | 140 local ok, err = stream:feed(data); |
139 if not ok then | 141 if not ok then |
140 module:log("warn", "Parse error: %s", err); | 142 module:log("warn", "Parse error in %s at %d+%d: %s", filename, item.offset, item.length, err); |
141 end | 143 end |
142 if result then | 144 if result then |
143 local stanza = result; | 145 local stanza = result; |
144 result = nil; | 146 result = nil; |
145 return item.id, stanza, item.when, item.with; | 147 return item.id, stanza, item.when, item.with; |