core.portmanager: Fix traceback on attempt to get non-existent service
authorKim Alvefur <zash@zash.se>
Tue, 22 Feb 2022 13:41:05 +0100
changeset 12316 8119a58b3a5c
parent 12315 bc30e1b9ad89
child 12317 469e4453ed01
core.portmanager: Fix traceback on attempt to get non-existent service If there's no such interface:port then `data` is nil and `data.service` errors.
core/portmanager.lua
--- a/core/portmanager.lua	Tue Feb 22 14:17:27 2022 +0100
+++ b/core/portmanager.lua	Tue Feb 22 13:41:05 2022 +0100
@@ -216,7 +216,9 @@
 end
 
 function get_service_at(interface, port)
-	local data = active_services:search(nil, interface, port)[1][1];
+	local data = active_services:search(nil, interface, port);
+	if not data or not data[1] or not data[1][1] then return nil, "not-found"; end
+	data = data[1][1];
 	return data.service, data.server;
 end