Skip to content

Commit 70cfa3b

Browse files
authored
Merge pull request #6 from twof/remove-trys
Trys removed
2 parents e15d364 + 9868493 commit 70cfa3b

3 files changed

Lines changed: 37 additions & 37 deletions

File tree

Sources/CrudRouter/ControllerProtocols/Crudable.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public protocol Crudable: ControllerProtocol {
88
at path: PathComponentsRepresentable...,
99
parent relation: KeyPath<ChildType, Parent<ChildType, ParentType>>,
1010
_ either: OnlyExceptEither<ParentRouterMethod>,
11-
relationConfiguration: ((CrudParentController<ChildType, ParentType>) throws -> Void)?
12-
) throws where
11+
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?
12+
) where
1313
ParentType: Model & Content,
1414
ChildType.Database == ParentType.Database,
1515
ParentType.ID: Parameter
@@ -18,8 +18,8 @@ public protocol Crudable: ControllerProtocol {
1818
at path: PathComponentsRepresentable...,
1919
children relation: KeyPath<ChildType, Children<ChildType, ChildChildType>>,
2020
_ either: OnlyExceptEither<ChildrenRouterMethod>,
21-
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) throws -> Void)?
22-
) throws where
21+
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) -> Void)?
22+
) where
2323
ChildChildType: Model & Content,
2424
ChildType.Database == ChildChildType.Database,
2525
ChildChildType.ID: Parameter
@@ -28,8 +28,8 @@ public protocol Crudable: ControllerProtocol {
2828
at path: PathComponentsRepresentable...,
2929
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
3030
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod>,
31-
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?
32-
) throws where
31+
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?
32+
) where
3333
ChildChildType: Content,
3434
ChildType.Database == ThroughType.Database,
3535
ChildChildType.ID: Parameter,
@@ -43,8 +43,8 @@ public protocol Crudable: ControllerProtocol {
4343
at path: PathComponentsRepresentable...,
4444
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
4545
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod>,
46-
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?
47-
) throws where
46+
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?
47+
) where
4848
ChildChildType: Content,
4949
ChildType.Database == ThroughType.Database,
5050
ChildChildType.ID: Parameter,
@@ -60,8 +60,8 @@ extension Crudable {
6060
at path: PathComponentsRepresentable...,
6161
parent relation: KeyPath<ChildType, Parent<ChildType, ParentType>>,
6262
_ either: OnlyExceptEither<ParentRouterMethod> = .only([.read, .update]),
63-
relationConfiguration: ((CrudParentController<ChildType, ParentType>) throws -> Void)?=nil
64-
) throws where
63+
relationConfiguration: ((CrudParentController<ChildType, ParentType>) -> Void)?=nil
64+
) where
6565
ParentType: Model & Content,
6666
ChildType.Database == ParentType.Database,
6767
ParentType.ID: Parameter {
@@ -81,17 +81,17 @@ extension Crudable {
8181
controller = CrudParentController(relation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
8282
}
8383

84-
try controller.boot(router: self.router)
84+
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }
8585

86-
try relationConfiguration?(controller)
86+
relationConfiguration?(controller)
8787
}
8888

8989
public func crud<ChildChildType>(
9090
at path: PathComponentsRepresentable...,
9191
children relation: KeyPath<ChildType, Children<ChildType, ChildChildType>>,
9292
_ either: OnlyExceptEither<ChildrenRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
93-
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) throws -> Void)?=nil
94-
) throws where
93+
relationConfiguration: ((CrudChildrenController<ChildChildType, ChildType>) -> Void)?=nil
94+
) where
9595
ChildChildType: Model & Content,
9696
ChildType.Database == ChildChildType.Database,
9797
ChildChildType.ID: Parameter {
@@ -110,17 +110,17 @@ extension Crudable {
110110
controller = CrudChildrenController<ChildChildType, ChildType>(childrenRelation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
111111
}
112112

113-
try controller.boot(router: self.router)
113+
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }
114114

115-
try relationConfiguration?(controller)
115+
relationConfiguration?(controller)
116116
}
117117

118118
public func crud<ChildChildType, ThroughType>(
119119
at path: PathComponentsRepresentable...,
120120
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
121121
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
122-
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?=nil
123-
) throws where
122+
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?=nil
123+
) where
124124
ChildChildType: Content,
125125
ChildType.Database == ThroughType.Database,
126126
ChildChildType.ID: Parameter,
@@ -145,17 +145,17 @@ extension Crudable {
145145
controller = CrudSiblingsController<ChildChildType, ChildType, ThroughType>(siblingRelation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
146146
}
147147

148-
try controller.boot(router: self.router)
148+
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }
149149

150-
try relationConfiguration?(controller)
150+
relationConfiguration?(controller)
151151
}
152152

153153
public func crud<ChildChildType, ThroughType>(
154154
at path: PathComponentsRepresentable...,
155155
siblings relation: KeyPath<ChildType, Siblings<ChildType, ChildChildType, ThroughType>>,
156156
_ either: OnlyExceptEither<ModifiableSiblingRouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
157-
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) throws -> Void)?=nil
158-
) throws where
157+
relationConfiguration: ((CrudSiblingsController<ChildChildType, ChildType, ThroughType>) -> Void)?=nil
158+
) where
159159
ChildChildType: Content,
160160
ChildType.Database == ThroughType.Database,
161161
ChildChildType.ID: Parameter,
@@ -179,8 +179,8 @@ extension Crudable {
179179
controller = CrudSiblingsController<ChildChildType, ChildType, ThroughType>(siblingRelation: relation, path: fullPath, router: self.router, activeMethods: allMethods.subtracting(Set(methods)))
180180
}
181181

182-
try controller.boot(router: self.router)
182+
do { try controller.boot(router: self.router) } catch { fatalError("I have no reason to expect boot to throw") }
183183

184-
try relationConfiguration?(controller)
184+
relationConfiguration?(controller)
185185
}
186186
}

Sources/CrudRouter/Extensions/Router+CRUD.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public extension Router {
66
_ path: PathComponentsRepresentable...,
77
register type: ModelType.Type,
88
_ either: OnlyExceptEither<RouterMethod> = .only([.read, .readAll, .create, .update, .delete]),
9-
relationConfiguration: ((CrudController<ModelType>) throws -> ())?=nil
10-
) throws where ModelType.ID: Parameter {
9+
relationConfiguration: ((CrudController<ModelType>) -> ())?=nil
10+
) where ModelType.ID: Parameter {
1111
let allMethods: Set<RouterMethod> = Set([.read, .readAll, .create, .update, .delete])
1212
let controller: CrudController<ModelType>
1313

@@ -18,8 +18,8 @@ public extension Router {
1818
controller = CrudController<ModelType>(path: path, router: self, activeMethods: allMethods.subtracting(Set(methods)))
1919
}
2020

21-
try controller.boot(router: self)
21+
do { try controller.boot(router: self) } catch { fatalError("I have no reason to expect boot to throw") }
2222

23-
try relationConfiguration?(controller)
23+
relationConfiguration?(controller)
2424
}
2525
}

Tests/CrudRouterTests/CrudRouterTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ func configure(_ config: inout Config, _ env: inout Environment, _ services: ino
8989
}
9090

9191
func routes(_ router: Router) throws {
92-
try router.crud(register: Galaxy.self) { controller in
93-
try controller.crud(children: \.planets)
92+
router.crud(register: Galaxy.self) { controller in
93+
controller.crud(children: \.planets)
9494
}
95-
try router.crud(register: Planet.self) { controller in
96-
try controller.crud(parent: \.galaxy)
97-
try controller.crud(siblings: \.tags)
95+
router.crud(register: Planet.self) { controller in
96+
controller.crud(parent: \.galaxy)
97+
controller.crud(siblings: \.tags)
9898
}
99-
try router.crud(register: Tag.self) { controller in
100-
try controller.crud(siblings: \.planets)
99+
router.crud(register: Tag.self) { controller in
100+
controller.crud(siblings: \.planets)
101101
}
102102
}
103103

@@ -165,7 +165,7 @@ final class CrudRouterTests: XCTestCase {
165165
func testBaseCrudRegistrationWithRouteName() throws {
166166
let router = EngineRouter.default()
167167

168-
try router.crud("planets", register: Planet.self)
168+
router.crud("planets", register: Planet.self)
169169

170170
XCTAssert(router.routes.isEmpty == false)
171171
XCTAssert(router.routes.count == 5)
@@ -181,7 +181,7 @@ final class CrudRouterTests: XCTestCase {
181181
func testBaseCrudRegistrationWithDefaultRoute() throws {
182182
let router = EngineRouter.default()
183183

184-
try router.crud(register: Planet.self)
184+
router.crud(register: Planet.self)
185185

186186
XCTAssert(router.routes.isEmpty == false)
187187
XCTAssert(router.routes.count == 5)

0 commit comments

Comments
 (0)