krz/domain-dig

an ios app for DNS & SSL analysis

clone: git clone https://gitbay.org/krz/domain-dig.git

5fe3aeb2cefc41b8b96d99d47d967eb7aa070c98

unsigned

author: Christian Cleberg <hello@cleberg.net> · 2026-07-24T23:34:35Z

fix: surface the real NWListener error and drop conflicting requiredLocalEndpoint (#30)

The Local API failed to start with a generic "Could not start Local API on
port 47821" and no actionable cause. Two problems:

1. The NWListener construction catch discarded the caught error and
   substituted a generic string, so the real NWError was never surfaced or
   logged. Now the underlying error is logged via stateLogger (matching the
   .failed branch) and appended to the thrown message.

2. parameters.requiredLocalEndpoint pinned 127.0.0.1:<port> while the same
   port was passed as the listener's on: argument. Pinning a required local
   endpoint conflicts with the listener's own port assignment; acceptLocalOnly
   already constrains binding to the local link. Dropped requiredLocalEndpoint,
   keeping acceptLocalOnly + allowLocalEndpointReuse.
 LocalAPIService.swift | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/LocalAPIService.swift b/LocalAPIService.swift
index 7d42128..cd12fb8 100644
--- a/LocalAPIService.swift
+++ b/LocalAPIService.swift
@@ -372,10 +372,6 @@ private final class LocalAPIServer: @unchecked Sendable {
         let parameters = NWParameters.tcp
         parameters.acceptLocalOnly = true
         parameters.allowLocalEndpointReuse = true
-        parameters.requiredLocalEndpoint = .hostPort(
-            host: .ipv4(IPv4Address.loopback),
-            port: NWEndpoint.Port(rawValue: UInt16(port)) ?? .any
-        )
 
         let listener: NWListener
         do {
@@ -384,7 +380,10 @@ private final class LocalAPIServer: @unchecked Sendable {
                 on: NWEndpoint.Port(rawValue: UInt16(port)) ?? .any
             )
         } catch {
-            throw LocalAPIServerError.serverStartFailed("Could not start Local API on port \(port).")
+            stateLogger("Failed: \(error.localizedDescription)")
+            throw LocalAPIServerError.serverStartFailed(
+                "Could not start Local API on port \(port): \(error.localizedDescription)"
+            )
         }
 
         listener.newConnectionHandler = { [weak self] connection in