-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Examine our compiler errors, and see if we can improve them #151
Comments
Yes, please. Here is one that drives me crazy:
Model:
I looked at the tests and the code looks alright. But I'm also just getting started with Diesel, so maybe I got something fundamentally wrong.. |
Switch the order of the columns on your model. It's trying to load the ID On Fri, Mar 18, 2016, 6:25 PM Jakob Gillich [email protected]
|
Oh wow, the order matters? I had no idea haha, thanks! |
For now, yes. We use indexed access instead of named access for performance On Fri, Mar 18, 2016, 6:30 PM Jakob Gillich [email protected]
|
I believe this is something that could be adressed (for now) in the guide as I just stumbled onto this as well, and it cost me around more than hour trying to find out what is going on. |
This is one you helped me with in gitter.im
adding an explicit type annotation to res solved this issue
|
I'm stuck with the below error and can't figure it out. The postgres table was created with Rails which manages the schema. Error(reformatted a bit for readability)
Model#[derive(Queryable)]
pub struct EndDevice {
pub id: i64,
pub eui: Option<String>,
pub app_key: Option<String>,
pub created_at: types::Timestamp,
pub updated_at: types::Timestamp,
} My DB Table
|
You shouldn't use |
Thank you @Eijebong, I got it working! For reference, this is working: use chrono::prelude::*;
#[derive(Queryable, Debug)]
pub struct EndDevice {
pub id: i64,
pub eui: Option<String>,
pub app_key: Option<String>,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
} |
Just saw rust-lang/rust#43000 and remembered this issue. I think we talked about it, but I'm not sure what the result was: Did we ever try something like the following? #![cfg_attr(feature="unstable", feature(on_unimplemented))]
#[cfg_attr(feature="unstable", rustc_on_unimplemented("To query … you can find more info in our docs at http://diesel.rs/")]
pub trait FromSql // … |
Yes. It doesn't give us the diagnostics we'd need in most cases, and rust-lang/rust#28894 and rust-lang/rust#33094 generally cause our error message to never show up anyway |
So I discussed this with some folks at the all hands this year, and This is something I'd like to make a major focus in 2019, hopefully looking into using a lint to help cases that we can't fix with other compiler hooks. A lot has changed since the last activity on this issue, so I'd like to renew the call for "please give us your bad error messages". If you can provide a small, single file script to reproduce the problem (e.g. something we'd be able to add as a compile test to Diesel), that would be much appreciated. |
#[derive(Queryable, Debug)]
pub struct User {
id: i32,
name: String,
}
#[derive(Insertable, Debug)]
pub struct NewUser {
name: String,
} I was getting a weird error when missing
Even with adding
But this could be fixed with Any idea if this could be improved? In the meantime I got another weird error.
This was because I mixed |
Generating a better error message for this case is unfortunately not possible as rust does not provide any API for proc macros to check which items are in scope and which are not in scope.
If there is no
You likely had an |
Thanks for the explanation, I didn't know zero sized struct is both a value and a type. While trying to make a minimal reproduction, I also find that you can't use |
At times, our compiler errors just flat out suck. While in this issue I will list several cases that I've specifically noticed are frequently problematic or have personally encountered, it should not be treated as exhaustive. If you've ever received a non-helpful compiler message from this lib, please comment with details. I do not think we will be able to fix all of them, but we should try to improve this issue before 1.0.
Truly "fixing" this will probably require significantly more control over the "trait not implemented" error, both on the trait itself (e.g. we can give a much better message for any case where
SelectableExpression
isn't implemented), and also at the function level (e.g. whenfind
doesn't work, we can probably be more specific, even though none of the traits failing are specific to find).As we attempt to make sure we create good error messages, we should update our
compile-fail
suite to be significantly more specific about the error messages we generate. While that will make those tests much more brittle, I'd rather have to update them frequently (and thus ensure that the new error message is still reasonable), than accidentally start generating a nonsense error for a common case.Problem Cases
Recommending
Expression
instead ofAsExpression
A consistent source of confusion is
rustc
's recommendation to implementExpression
,NonAggregate
, andQueryFragment
, when the missing piece is actuallyAsExpression
. Ultimately this is due to rust-lang/rust#28894. If we can't fix that issue in the language, we should probably just remove that blanket impl and brute force it instead (I'm honestly surprised the coherence rules haven't forced this already, I think this is the only blanket impl that's survived).Some types are too long to ever appear in error messages
Another case that we should look for is any case where
SelectStatement
orFilterQuerySource
end up in the final error message. It doesn't matter what trait is missing, the error messageSelectStatement<(type1, type2, type3, 10moretypes), (col1, col2, col3, 10morecolumns), InnerJoinQuerySource<left_table, right_table>, NoWhereClause, NoOrderClause, NoLimitClause, NoOffsetClause> does not implement AsQuery
will always be too noisy to be helpful. That specific error is actually one of the simpler cases, and even with that exact case, every type would have the fully qualified path, and be repeated 3 times (saying it looked atSelectStatement
,&SelectStatement
, and&mut SelectStatement
). It's not uncommon for that kind of error message to take up the entire terminal window.The text was updated successfully, but these errors were encountered: