@@ -16,19 +16,31 @@ public struct Config: Codable {
1616 public let additionalImports : [ String ] ?
1717 public let tableNamePattern : String ?
1818
19- struct NotFoundError : Error , CustomStringConvertible {
20- var description : String { " Config does not exist " }
19+ enum ConfigError : Error , CustomStringConvertible {
20+ case invalidURL( String )
21+ case notFound( searchPath: String )
22+
23+ var description : String {
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+ }
30+ }
2131 }
2232
2333 public init ( at path: String ) throws {
24- var url = URL ( fileURLWithPath: path)
34+ guard var url = URL ( string: path) else {
35+ throw ConfigError . invalidURL ( path)
36+ }
2537
2638 if url. lastPathComponent != " puresql.yaml " {
2739 url. appendPathComponent ( " puresql.yaml " )
2840 }
2941
3042 guard FileManager . default. fileExists ( atPath: url. path) else {
31- throw NotFoundError ( )
43+ throw ConfigError . notFound ( searchPath : url . path )
3244 }
3345
3446 let data = try Data ( contentsOf: url)
@@ -37,8 +49,10 @@ public struct Config: Codable {
3749 self = try decoder. decode ( Config . self, from: data)
3850 }
3951
40- public func project( at path: String ) -> Project {
41- 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+ }
4256
4357 return Project (
4458 generatedOutputFile: url. appendingPathComponent ( output ?? " Queries.swift " ) ,
0 commit comments