Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Commit 4c870f4

Browse files
author
Kevin Lundberg
committed
Remove underscores from switch case, and use do-catch pattern matching for slightly cleaner code
1 parent d215f84 commit 4c870f4

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

Sources/Unboxer.swift

+15-19
Original file line numberDiff line numberDiff line change
@@ -243,26 +243,22 @@ private extension Unboxer {
243243

244244
throw UnboxPathError.emptyKeyPath
245245
}
246-
} catch {
247-
if case UnboxError.pathError(let pathError, let partialPath) = error {
248-
switch pathError {
249-
case .emptyKeyPath,
250-
.invalidCollectionElementType(_),
251-
.invalidDictionaryKey(_):
252-
throw UnboxError.pathError(pathError, partialPath)
253-
case .missingKey(_),
254-
.invalidValue(_, _, _),
255-
.invalidDictionaryKeyType(_),
256-
.invalidDictionaryValue(_, _, _):
257-
throw UnboxError.pathError(pathError, "\(path).\(partialPath)")
258-
case let .invalidArrayElement(_, index, _):
259-
throw UnboxError.pathError(pathError, "\(path).\(index).\(partialPath)")
260-
}
261-
} else if let pathError = error as? UnboxPathError {
262-
throw UnboxError.pathError(pathError, path.description)
246+
} catch UnboxError.pathError(let pathError, let partialPath) {
247+
switch pathError {
248+
case .emptyKeyPath,
249+
.invalidCollectionElementType,
250+
.invalidDictionaryKey:
251+
throw UnboxError.pathError(pathError, partialPath)
252+
case .missingKey,
253+
.invalidValue,
254+
.invalidDictionaryKeyType,
255+
.invalidDictionaryValue:
256+
throw UnboxError.pathError(pathError, "\(path).\(partialPath)")
257+
case let .invalidArrayElement(_, index, _):
258+
throw UnboxError.pathError(pathError, "\(path).\(index).\(partialPath)")
263259
}
264-
265-
throw error
260+
} catch let pathError as UnboxPathError {
261+
throw UnboxError.pathError(pathError, path.description)
266262
}
267263
}
268264

0 commit comments

Comments
 (0)