-
-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The postgres::Error is hard to work with #353
Comments
None of the library internal structure require that you return errors as Strings (and therefore, do unnecessary dynamic allocation and type erasure). Why the hell are errors just strings, but presented as Lots of code in this library looks like this: return Err(io::Error::new(
io::ErrorKind::InvalidData,
"invalid message length",
)); This is what 90% of errors look like in this library, it's very bad style. Why does a simple String need to be wrapped in an IO error? Why does it need to be a String in the first place? It could just be: return Err(ParseError::InvalidMessageLength);
impl Display for ParseError {
/* snip */
match self {
InvalidMessageLength => write!(f, "invalid message length");
}
} Why is everything in this library just "errors are strings"? No pattern matching, no stability, English-only, no exhaustive matching ... why??? |
Sorry if my previous messages were a bit rude, I was in a bad mood. I'm working on a PR with strongly-typed errors, then you can see what I mean by "doing it correctly". If you are just doing the |
Don't be an asshole.
Yep, this is an oversight, and should be added.
This style of error is not uncommon. It's used in serde_json and hyper for example. Providing direct access to the backing enum overly constrains the implementation. hyperium/hyper#1131 has more background.
In which library? io::Error is not the return type of anything other than postgres-protocol. Errors are only returned from that if either Postgres is broken or we are. Why does a user care about the distinction between the database returning a 5 byte buffer when we're expecting a 4 byte buffer, and returning a 3 byte buffer?
"Everything" is not a
What does that enum look like? What is the set of all possible TLS errors? What is the set of all possible conversion errors? No, I have not erased all type information. You can downcast
You are aware that postgres-protocol is only one part of this library, right?
"exhaustive matching" means "no ability to extend without making a breaking change".
What does Tokio have to do with any of this? |
Having access to the enum error::Kind would certainly make for more straight forward usage. |
as_tls()
function. There is no way to get the inner type of the TLS error, even though the library internally does have this information.Error(Box<ErrorKind>)
(and ErrorKind is simple enum) instead of just having theErrorKind
asError
in the public API? It completely prevents pattern matching:instead of:
All that the overcomplicated
postgres::Error
is doing is manually implementing pattern-matching. But now I can't match on two errors at the same time, ... why are you doing this??? If you want to prevent outsiders from creating aErrorKind
, that in itself is fine, but you could just make a function that returns a read-only reference to the inner error kind, not prevent pattern matching completely.I can't use the
.description()
and.cause()
methods, since these error strings have to be localized in the real code. If I had an enum, I could easily do this, as this is standard error case for Rust crates.Why is everything
Box<Error + Sync + Send>
when all you are doing in the library is putting Strings into thatBox
? Why isn't this an enum - you've simply erased all type information and now all errors are strings. Just use enums for returning errors. At the very least you could useString
instead ofBox<Error + Sync + Send>
.Why is everything in this library an
io::Error::Other("String")
? Things like parsing errors don't belong in the category of IO errors.The text was updated successfully, but these errors were encountered: