Skip to content

Commit

Permalink
Better error for URLs (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarsen authored Nov 14, 2016
2 parents ba0c55e + 72d5814 commit 4bdc613
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/ValueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ extension Set where Element: ValueType {

extension URL: ValueType {
public static func value(from object: Any) throws -> URL {
guard let urlString = object as? String, let objectValue = URL(string: urlString) else {
throw MarshalError.typeMismatch(expected: self, actual: type(of: object))
guard let urlString = object as? String else {
throw MarshalError.typeMismatch(expected: String.self, actual: type(of: object))
}
guard let objectValue = URL(string: urlString) else {
throw MarshalError.typeMismatch(expected: "valid URL", actual: urlString)
}
return objectValue
}
Expand Down

0 comments on commit 4bdc613

Please sign in to comment.