# HG changeset patch # User Kim Alvefur # Date 1546182195 -3600 # Node ID 99199b53019f6d56db83085ebf8495d759a30158 # Parent c8240f931a68a66b7b23ec9bab073ab454cad263 core.moduleapi: Use util.error for :send_iq errors diff -r c8240f931a68 -r 99199b53019f core/moduleapi.lua --- a/core/moduleapi.lua Sun Dec 30 14:26:58 2018 +0100 +++ b/core/moduleapi.lua Sun Dec 30 16:03:15 2018 +0100 @@ -15,6 +15,7 @@ local resolve_relative_path = require"util.paths".resolve_relative_path; local st = require "util.stanza"; local cache = require "util.cache"; +local errutil = require "util.error"; local promise = require "util.promise"; local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; @@ -367,7 +368,10 @@ local iq_cache = self._iq_cache; if not iq_cache then iq_cache = cache.new(256, function (_, iq) - iq.reject("evicted"); + iq.reject(errutil.new({ + type = "wait", condition = "resource-constraint", + text = "evicted from iq tracking cache" + })); self:unhook(iq.result_event, iq.result_handler); self:unhook(iq.error_event, iq.error_handler); end); @@ -393,20 +397,29 @@ local function error_handler(event) if event.stanza.attr.from == stanza.attr.to then - reject(event); + local error_type, condition, text = event.stanza:get_error(); + local err = errutil.new({ type = error_type, condition = condition, text = text }, event); + reject(err); return true; end end if iq_cache:get(cache_key) then - error("choose another iq stanza id attribute") + reject(errutil.new({ + type = "modify", condition = "conflict", + text = "iq stanza id attribute already used", + })); + return; end self:hook(result_event, result_handler); self:hook(error_event, error_handler); local timeout_handle = self:add_timer(timeout or 120, function () - reject("timeout"); + reject(errutil.new({ + type = "wait", condition = "remote-server-timeout", + text = "IQ stanza timed out", + })); self:unhook(result_event, result_handler); self:unhook(error_event, error_handler); iq_cache:set(cache_key, nil); @@ -420,7 +433,10 @@ }); if not ok then - reject("cache insertion failure"); + reject(errutil.new({ + type = "wait", condition = "internal-server-error", + text = "Could not store IQ tracking data" + })); return; end diff -r c8240f931a68 -r 99199b53019f plugins/mod_admin_telnet.lua --- a/plugins/mod_admin_telnet.lua Sun Dec 30 14:26:58 2018 +0100 +++ b/plugins/mod_admin_telnet.lua Sun Dec 30 16:03:15 2018 +0100 @@ -1111,9 +1111,6 @@ wait(); if ret then return true, "pong from " .. ret.stanza.attr.from; - elseif type(err) == "table" and st.is_stanza(err.stanza) then - local t, cond, text = err.stanza:get_error(); - return false, text or cond or t; else return false, tostring(err); end