You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
protocol Response {}
protocol Resource {
associatedtype ResponseType: Response
var baseURL: URL { get }
var path: String { get }
var method: HTTPMethod { get }
var headers: [String: String]? { get }
var parameters: [String: Any]? { get }
func parse(response: Data) -> Result<ResponseType, Error>
}
But I get the error Using 'Error' as a concrete type conforming to protocol 'Error' is not supported on the final line. I understand this is because of the way Result is declared as Result<T, Error : Error> ..., thus forcing the caller to provide a concrete Error subtype.
The problem I run into is that in my parse() method I would like to just throw up any errors produced by my JSON parsing library (or whatever.) But they're declared as Swift.Error, which means I can't do that.
I understand from reading other issues that if Result was declared Result<T> (and just implied Swift.Error as its error type) it'd degenerate to just an Either and the maintainers don't want that.
But is there a neat way I can get around this without having to explicitly wrap every Error subtype my parse() might throw?
The text was updated successfully, but these errors were encountered:
So, in practice, the answer to the question in my last sentence is "No, just declare parse to return func parse(response: Data) -> Result<ResponseType, AnyError>", which works fine in practice.
I'm attempting to write a protocol like this:
But I get the error
Using 'Error' as a concrete type conforming to protocol 'Error' is not supported
on the final line. I understand this is because of the way Result is declared asResult<T, Error : Error> ...
, thus forcing the caller to provide a concrete Error subtype.The problem I run into is that in my
parse()
method I would like to just throw up any errors produced by my JSON parsing library (or whatever.) But they're declared asSwift.Error
, which means I can't do that.I understand from reading other issues that if Result was declared
Result<T>
(and just impliedSwift.Error
as its error type) it'd degenerate to just an Either and the maintainers don't want that.But is there a neat way I can get around this without having to explicitly wrap every Error subtype my
parse()
might throw?The text was updated successfully, but these errors were encountered: