@@ -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 " ) ,
0 commit comments