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

Commit

Permalink
Remove underscores from switch case, and use do-catch pattern matchin…
Browse files Browse the repository at this point in the history
…g for slightly cleaner code
  • Loading branch information
Kevin Lundberg committed Jan 19, 2018
1 parent d215f84 commit 4c870f4
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions Sources/Unboxer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,26 +243,22 @@ private extension Unboxer {

throw UnboxPathError.emptyKeyPath
}
} catch {
if case UnboxError.pathError(let pathError, let partialPath) = error {
switch pathError {
case .emptyKeyPath,
.invalidCollectionElementType(_),
.invalidDictionaryKey(_):
throw UnboxError.pathError(pathError, partialPath)
case .missingKey(_),
.invalidValue(_, _, _),
.invalidDictionaryKeyType(_),
.invalidDictionaryValue(_, _, _):
throw UnboxError.pathError(pathError, "\(path).\(partialPath)")
case let .invalidArrayElement(_, index, _):
throw UnboxError.pathError(pathError, "\(path).\(index).\(partialPath)")
}
} else if let pathError = error as? UnboxPathError {
throw UnboxError.pathError(pathError, path.description)
} catch UnboxError.pathError(let pathError, let partialPath) {
switch pathError {
case .emptyKeyPath,
.invalidCollectionElementType,
.invalidDictionaryKey:
throw UnboxError.pathError(pathError, partialPath)
case .missingKey,
.invalidValue,
.invalidDictionaryKeyType,
.invalidDictionaryValue:
throw UnboxError.pathError(pathError, "\(path).\(partialPath)")
case let .invalidArrayElement(_, index, _):
throw UnboxError.pathError(pathError, "\(path).\(index).\(partialPath)")
}

throw error
} catch let pathError as UnboxPathError {
throw UnboxError.pathError(pathError, path.description)
}
}

Expand Down

0 comments on commit 4c870f4

Please sign in to comment.