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
AsChangeset and Insertable produce unhelpful error messages #2793
Comments
|
That's for opening this issue. After having spend some time to dig into this I fear there is no much we can do here. From a technical point of view there are two possibilities to generate this "nicer" error message":
The only thing that could actually be done is to improve this error message to say something more meaningful. We are happy to receive a PR doing that. |
|
I think there is a 3rd option: Make the proc-macro return something like syn::Error::new(self.meta.span(), format!(
"Expected valid identifier, found `{name}`. Diesel automatically renames invalid identifiers, perhaps you meant to write `{name}_`?",
name = self.name().segments.first().unwrap().ident.clone()
)).into_compile_error()This will produce an error message like This is much better than using |
Why doesn't anyone give him some credit? It's a nice solution! |
|
@Pyzyryab Feel free to submit a PR implementing this strategy + adding some tests to show that it works via tests. Otherwise our issue tracker is for our contributors to track bugs and regressions. It's not a place for general discussion. |


Consider the following code (using
AsChangesetinstead / in addition toInsertableproduces the same error message):This code is wrong because eventhough the table has a column called type, the auto-generated
schema.rsfile renames that to type_ to avoid using a keyword as an identifier, and that's the column name that has to be used. Unfortunately, the error message produced by the macro has an unhelpful message and an incorrect span:Ideally, the error message would look similar to this:
This error message does not only help when trying to use a name that is an invalid identifier in rust, but also when there is a typo in the column name.
Related: #2792 (comment)
The text was updated successfully, but these errors were encountered: