I'm designing an API for a type that seems like a good fit for
LosslessStringConvertible - it represents a database connection string containing information about the hosts to connect to, configuration options, and so on, and given an instance of this type it is possible to construct a lossless string representation of it.
However, one concern I have with conforming to the protocol is the required failable initializer, which provides no way for me to tell the user what the problem with the input was - and there are a number of different things that could be wrong. In general I tend to only use failable inits when the failure case is really obvious.
Some things I've considered...
- Maybe this means my type is not a good fit for such a protocol after all? Would the protocol actually provide that much value to users beyond what it signals about the type having a lossless string representation?
- Maybe I could work around this by providing a second throwing initializer which throws a more descriptive error, and use some parameter label to make it unambiguous from the failable init, and users who want specific error info can use that one?
Curious to hear any thoughts on this