diff --git a/Sources/phbar/Models/PHBarDelegate/PHBarDelegate+Lifecycle.swift b/Sources/phbar/Models/PHBarDelegate/PHBarDelegate+Lifecycle.swift index 2e1d408..1a138fb 100644 --- a/Sources/phbar/Models/PHBarDelegate/PHBarDelegate+Lifecycle.swift +++ b/Sources/phbar/Models/PHBarDelegate/PHBarDelegate+Lifecycle.swift @@ -10,7 +10,7 @@ extension PHBarDelegate { do { controller = try factory.make(for: screen) } catch { - stderr("skipping screen \(screen.localizedName): \(error)") + stderr("skipping screen \(screen.localizedName): \(error.localizedDescription)") return false } let window = BarWindow(controller: controller) diff --git a/Sources/phbar/Models/PHConfig/PHConfig+Loading.swift b/Sources/phbar/Models/PHConfig/PHConfig+Loading.swift index 393c1f9..5054acb 100644 --- a/Sources/phbar/Models/PHConfig/PHConfig+Loading.swift +++ b/Sources/phbar/Models/PHConfig/PHConfig+Loading.swift @@ -3,39 +3,34 @@ import TOML extension PHConfig { /// Load configuration from the resolved config directory - /// (see `PHPaths`). If the file doesn't exist or fails to parse, the - /// bundled default is used. + /// (see `PHPaths`). If the file doesn't exist or fails to parse, + /// the execution is interrupted. static func load() throws -> PHConfig { let url = PHPaths.configDirectory.appending(path: "config.toml") if FileManager.default.fileExists(atPath: url.relativePath) { return try load(from: url) } else { - return try loadFromBundle() - } - } + throw PHBar.Error( + """ + Configuration file not found. + Make sure to have a file named `config.toml` inside the + directory: `\(url.deletingLastPathComponent().relativePath)` - /// Load the bundled configuration. - /// If the file doesn't exist or fails to parse, the execution is interrupted. - static private func loadFromBundle() throws -> PHConfig { - guard - let defaultConfig = Bundle.module.url( - forResource: "config", - withExtension: "toml" - )?.resolvingSymlinksInPath() - else { - throw PHBar.Error("Failed to load config file") + Tip: If you've never used phbar before, run the `phbar install` command + to automatically generate the required configuration files. + """ + ) } - return try load(from: defaultConfig) } /// Decode configuration from a file at URL. /// If the file doesn't exist or fails to parse, the execution is interrupted. static private func load(from url: URL) throws -> PHConfig { guard let data = try? Data(contentsOf: url), - let contents = String(data: data, encoding: .utf8) + let contents = String(data: data, encoding: .utf8), !contents.isEmpty else { - throw PHBar.Error("Failed to load config file") + throw PHBar.Error("Configuration file not readable or empty.") } return try load(from: contents) @@ -53,7 +48,7 @@ extension PHConfig { // resolve the same set. return config.resolvingEnv() } catch { - throw PHBar.Error("Failed to parse config file", underlyingError: error) + throw PHBar.Error("Configuration file not valid", underlyingError: error) } } }