Skip to content

Commit 201df16

Browse files
author
Eric Miller
committed
Better error handling on initial configuration load
1 parent cd4b264 commit 201df16

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Sources/UBKit/UBKit.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ public final class UBKit {
1414
public func run(_ completion: @escaping ((Error?) -> Void)) {
1515
let workingPath = fileManager.currentDirectoryPath
1616
do {
17-
if let fileData = fileManager.contents(atPath: workingPath.appending("/ubconfig.json")) {
18-
if let configJSON = try JSONSerialization.jsonObject(with: fileData, options: .allowFragments) as? [String : String] {
19-
guard let config = Config(json: configJSON) else {
20-
completion(UBKitError.invalidConfigFile)
21-
return
22-
}
23-
kitManager = UBKitManager(config: config)
17+
guard let fileData = fileManager.contents(atPath: workingPath.appending("/ubconfig.json")) else {
18+
completion(UBKitError.invalidFolder(workingPath.appending("/ubconfig.json")))
19+
return
20+
}
21+
if let configJSON = try JSONSerialization.jsonObject(with: fileData, options: .allowFragments) as? [String : String] {
22+
guard let config = Config(json: configJSON) else {
23+
completion(UBKitError.invalidConfigFile)
24+
return
2425
}
25-
26+
kitManager = UBKitManager(config: config)
2627
}
28+
2729
} catch {
28-
completion(UBKitError.invalidFolder(workingPath.appending("/ubconfig.json")))
30+
completion(error)
31+
return
2932
}
3033

3134
let taskResult = kitManager.performTasks()

0 commit comments

Comments
 (0)