Software /
code /
prosody
Comparison
net/resolvers/service.lua @ 11901:26406ce35e20
net.connect: Propagate last error message from resolvers
Previously it would only say "unable to resolve server" for all DNS
problems. While "NoError in A lookup" might not make much sense to
users, it should help in debugging more than the previous generic error.
Friendlier errors will be future work.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Nov 2021 16:52:55 +0100 |
parent | 11710:26a8cc9d9eb7 |
child | 12025:6ed7fd28f5e3 |
comparison
equal
deleted
inserted
replaced
11900:60676b607b6d | 11901:26406ce35e20 |
---|---|
18 end | 18 end |
19 local next_target = table.remove(self.targets, 1); | 19 local next_target = table.remove(self.targets, 1); |
20 self.resolver = basic.new(unpack(next_target, 1, 4)); | 20 self.resolver = basic.new(unpack(next_target, 1, 4)); |
21 end | 21 end |
22 self.resolver:next(function (...) | 22 self.resolver:next(function (...) |
23 if self.resolver then | |
24 self.last_error = self.resolver.last_error; | |
25 end | |
23 if ... == nil then | 26 if ... == nil then |
24 self.resolver = nil; | 27 self.resolver = nil; |
25 self:next(cb); | 28 self:next(cb); |
26 else | 29 else |
27 cb(...); | 30 cb(...); |
55 end | 58 end |
56 | 59 |
57 if #answer == 0 then | 60 if #answer == 0 then |
58 if self.extra and self.extra.default_port then | 61 if self.extra and self.extra.default_port then |
59 table.insert(targets, { self.hostname, self.extra.default_port, self.conn_type, self.extra }); | 62 table.insert(targets, { self.hostname, self.extra.default_port, self.conn_type, self.extra }); |
63 else | |
64 self.last_error = "zero SRV records found"; | |
60 end | 65 end |
61 ready(); | 66 ready(); |
62 return; | 67 return; |
63 end | 68 end |
64 | 69 |
65 if #answer == 1 and answer[1].srv.target == "." then -- No service here | 70 if #answer == 1 and answer[1].srv.target == "." then -- No service here |
71 self.last_error = "service explicitly unavailable"; | |
66 ready(); | 72 ready(); |
67 return; | 73 return; |
68 end | 74 end |
69 | 75 |
70 table.sort(answer, function (a, b) return a.srv.priority < b.srv.priority end); | 76 table.sort(answer, function (a, b) return a.srv.priority < b.srv.priority end); |
71 for _, record in ipairs(answer) do | 77 for _, record in ipairs(answer) do |
72 table.insert(targets, { record.srv.target, record.srv.port, self.conn_type, self.extra }); | 78 table.insert(targets, { record.srv.target, record.srv.port, self.conn_type, self.extra }); |
73 end | 79 end |
80 else | |
81 self.last_error = err; | |
74 end | 82 end |
75 ready(); | 83 ready(); |
76 end, "_" .. self.service .. "._" .. self.conn_type .. "." .. self.hostname, "SRV", "IN"); | 84 end, "_" .. self.service .. "._" .. self.conn_type .. "." .. self.hostname, "SRV", "IN"); |
77 end | 85 end |
78 | 86 |