Skip to content

Commit f13a4b8

Browse files
committed
Fixed other call sites
1 parent 38440c5 commit f13a4b8

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

Sources/Compiler/Config.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,31 @@ public struct Config: Codable {
1616
public let additionalImports: [String]?
1717
public let tableNamePattern: String?
1818

19-
struct NotFoundError: Error, CustomStringConvertible {
20-
let searchPath: String
19+
enum ConfigError: Error, CustomStringConvertible {
20+
case invalidURL(String)
21+
case notFound(searchPath: String)
2122

2223
var description: String {
23-
"Config does not exist in '\(searchPath)'"
24+
switch self {
25+
case .invalidURL(let url):
26+
"Invalid URL '\(url)'"
27+
case .notFound(let searchPath):
28+
"Config does not exist in '\(searchPath)'"
29+
}
2430
}
2531
}
2632

2733
public init(at path: String) throws {
2834
guard var url = URL(string: path) else {
29-
throw NotFoundError(searchPath: path)
35+
throw ConfigError.invalidURL(path)
3036
}
3137

3238
if url.lastPathComponent != "puresql.yaml" {
3339
url.appendPathComponent("puresql.yaml")
3440
}
3541

3642
guard FileManager.default.fileExists(atPath: url.path) else {
37-
throw NotFoundError(searchPath: url.path)
43+
throw ConfigError.notFound(searchPath: url.path)
3844
}
3945

4046
let data = try Data(contentsOf: url)
@@ -43,8 +49,10 @@ public struct Config: Codable {
4349
self = try decoder.decode(Config.self, from: data)
4450
}
4551

46-
public func project(at path: String) -> Project {
47-
let url = URL(fileURLWithPath: path)
52+
public func project(at path: String) throws -> Project {
53+
guard let url = URL(string: path) else {
54+
throw ConfigError.invalidURL(path)
55+
}
4856

4957
return Project(
5058
generatedOutputFile: url.appendingPathComponent(output ?? "Queries.swift"),

Sources/PureSQLCLI/GenerateCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct GenerateCommand: AsyncParsableCommand {
3636

3737
mutating func run() async throws {
3838
let config = try Config(at: path)
39-
var project = config.project(at: path)
39+
var project = try config.project(at: path)
4040

4141
if let overrideOutput, let url = URL(string: overrideOutput) {
4242
project.generatedOutputFile = url

Sources/PureSQLCLI/MigrationsCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct MigrationsCommand: ParsableCommand {
2323

2424
func run() throws {
2525
let config = try Config(at: path)
26-
let project = config.project(at: path)
26+
let project = try config.project(at: path)
2727
try project.addMigration()
2828
}
2929
}

Sources/PureSQLCLI/QueriesCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct QueriesCommand: ParsableCommand {
2525

2626
func run() throws {
2727
let config = try Config(at: path)
28-
let project = config.project(at: path)
28+
let project = try config.project(at: path)
2929

3030
guard !project.doesQueryExist(withName: name) else {
3131
throw SQLError.queryAlreadyExists(fileName: name)

0 commit comments

Comments
 (0)