Skip to content

Commit 62c24f5

Browse files
committed
Include host name in PreviewServer error messages
If there’s a problem binding to a local port, the specific host name might be relevant.
1 parent 45f9809 commit 62c24f5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Sources/SwiftDocCUtilities/PreviewServer/PreviewServer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ final class PreviewServer {
4545
/// The server did not find the content directory.
4646
case pathNotFound(String)
4747
/// Cannot bind the server to the given address
48-
case cannotStartServer(port: Int)
48+
case cannotStartServer(host: String, port: Int)
4949
/// The given port is not available
50-
case portNotAvailable(port: Int)
50+
case portNotAvailable(host: String, port: Int)
5151

5252
var errorDescription: String {
5353
switch self {
5454
case .failedToStart: return "Failed to start preview server"
5555
case .pathNotFound(let path): return "The preview content path '\(path)' is not found"
56-
case .cannotStartServer(let port): return "Can't start the preview server on port \(port)"
57-
case .portNotAvailable(let port): return "Port \(port) is not available at the moment, "
56+
case .cannotStartServer(let host, let port): return "Can't start the preview server on host \(host) and port \(port)"
57+
case .portNotAvailable(let host, let port): return "Port \(port) is not available on host \(host) at the moment, "
5858
+ "try a different port number by adding the option '--port XXXX' "
5959
+ "to your command invocation where XXXX is the desired (free) port."
6060
}
@@ -154,13 +154,13 @@ final class PreviewServer {
154154
} catch let error as NIO.IOError where error.errnoCode == EADDRINUSE {
155155
// The given port is not available.
156156
switch bindTo {
157-
case .localhost(_, let port): throw Error.portNotAvailable(port: port)
157+
case .localhost(let host, let port): throw Error.portNotAvailable(host: host, port: port)
158158
default: throw error
159159
}
160160
} catch {
161161
// Cannot bind the given address/port.
162162
switch bindTo {
163-
case .localhost(_, let port): throw Error.cannotStartServer(port: port)
163+
case .localhost(let host, let port): throw Error.cannotStartServer(host: host, port: port)
164164
default: throw error
165165
}
166166
}

0 commit comments

Comments
 (0)