bridge: the discovery answer is published through send()

The answer on <root>/discover_r called the publisher directly; a publisher
that threw or rejected was only caught by the handler meant for listeners
of "discover". It now takes the path of every device message: send()
resolves, and a failure goes to the "error" event when somebody listens.
A test covers a publish that fails, throws and rejects, with and without
an "error" listener: receive() resolves each time and "discover" is not
emitted.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 21:15:47 +00:00
parent 94b13f733a
commit d12767f9a7
4 changed files with 40 additions and 15 deletions

View file

@ -174,12 +174,11 @@ class Alex2MQTT extends events_1.EventEmitter {
this.log("Discovery request received, getting device json...");
const deviceArray = this.describeDevices();
this.lastDiscoveryAt = new Date().toISOString();
const result = await this.publisher.publish(topics.discoverReply(this.rootTopic), deviceArray);
if (!result.ok) {
this.fail(result.error);
// send(), as for every message of a device: a publisher that throws or rejects is reported like one that fails
const topic = await (0, transport_js_1.send)(this.publisher, topics.discoverReply(this.rootTopic), () => deviceArray, (err) => this.fail(err));
if (topic === "")
return;
}
this.log(`Discovery payloads published to ${result.topic}`, deviceArray);
this.log(`Discovery payloads published to ${topic}`, deviceArray);
this.emit("discover", deviceArray.length);
}
// The endpoint objects of a discovery answer. What check() says about a device is logged, each line once. A device