From 5fe3aeb2cefc41b8b96d99d47d967eb7aa070c98 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Fri, 24 Jul 2026 18:34:35 -0500 Subject: 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: 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 -- cgit v1.2.3