From e01e475ede08002b5c8d6854a01365d5b248fe8a Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on Debian Linux)" <rob@synchro.net> Date: Sat, 25 Feb 2023 14:58:57 -0800 Subject: [PATCH] Throw a more helpful exception when no nameservers specified/available My /etc/resolv.conf was wiped by Network Manager (gee, thanks), so ircd.js was throwing the following unhelpful exceptions when starting up: Feb 25 13:47:51 git jsexec[19108]: !JavaScript : uncaught exception: Unable to create any sockets Feb 25 13:47:51 git jsexec[19108]: !JavaScript : uncaught exception: Unable to create any sockets First, instead of throwing a string, throw an Error object so we can actually know where the exception ocurred. Please, everyone, throw Errors not Strings. Second, throw a different more helpful exception if there are no nameservers specified in the DNS constructor or configured on the system. --- exec/load/dns.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exec/load/dns.js b/exec/load/dns.js index c31a71a4e5..fcdb219665 100644 --- a/exec/load/dns.js +++ b/exec/load/dns.js @@ -51,6 +51,8 @@ function DNS(synchronous, servers) { if (servers === undefined) servers = system.name_servers; + if (!servers || !servers.length) + throw new Error("No nameservers specified in constructor or configured in system"); servers.forEach(function(server) { var sock = new Socket(SOCK_DGRAM, "dns", server.indexOf(':') >= 0); sock.bind(); @@ -63,7 +65,7 @@ function DNS(synchronous, servers) { }, this); if (this.sockets.length < 1) - throw('Unable to create any sockets'); + throw new Error('Unable to create any sockets'); this.increment_id = function() { var ret = nextid; -- GitLab