From 4baa6a697372d3a45dcb8cd2b2680304d73d86aa Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Thu, 10 Feb 2022 17:16:28 +0100 Subject: [PATCH] Print errors on config file load --- Sources/App/configure.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index aec0d64..0112d72 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -98,17 +98,26 @@ private func createFileIfNeeded(at path: URL) throws { try Data().write(to: path) } +private func readConfig(at path: URL) throws -> URL { + do { + let logPath = try String(contentsOf: path) + .trimmingCharacters(in: .whitespaces) + return URL(fileURLWithPath: logPath) + } catch { + log("Failed to read configuration file at \(path.path): \(error)") + throw error + } +} + // configures your application public func configure(_ app: Application) throws { // uncomment to serve files from /Public folder // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) app.http.server.configuration.port = 9001 - let configFile = URL(fileURLWithPath: app.directory.resourcesDirectory) + let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory) .appendingPathComponent("paths.conf") - let logPath = try String(contentsOf: configFile) - .trimmingCharacters(in: .whitespaces) - let logFile = URL(fileURLWithPath: logPath) + let logFile = try readConfig(at: configPath) let listDirectory = URL(fileURLWithPath: app.directory.publicDirectory) .appendingPathComponent("lists")