- Notifications
You must be signed in to change notification settings - Fork515
Description
Onmaster
, everything returns aResult<T, ~str>
. Onnative
, error "handling" is task failure. Neither of these options are particularly great.
TheResult
strategy imposes an annoying burden on users who don't care about handling SQL syntax errors in the common case.~str
is also not the appropriate type for errors, but that's more easily fixable.
On the other hand, usersdo sometimes want to do reasonable things with failure, especially when connecting and potentially when querying (e.g. if you wanted to rewrite psql).
One option is to have something like
impl PostgresConnection { pub fn connect(url: &Url) -> PostgresConnection { match PostgresConnection::try_connect(url) { Ok(conn) => conn, Err(err) => fail!(err) } } pub fn try_connect(url: &Url) -> Result<PostgresConnection, PostgresConnectionError> { .... }}
and so on for all of the relevant methods. I think this is probably the most workable solution.
Whatever the solution is, the error object type should be robust. We should be able to parse the SQLSTATE value of the ErrorResult to get things likeNotNullViolation
vsForeignKeyViolation
.