Skip to content
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

Include the name of the column in InvalidColumnType errors #541

Merged
merged 1 commit into from
Jun 26, 2019

Conversation

thomcc
Copy link
Member

@thomcc thomcc commented Jun 25, 2019

We're hitting this in the wild on firefox-ios and knowing that some query has a Null for column 3 is... not particularly actionable. The column name would at least give us a starting place.

I've also made it perform bounds checking on the index in column_name, even though it just panics on out of bounds for now, and refactored that code a little.

It would be nice to get this in a release after it lands, but if that ends up not being possible timing-wise I can just point at my fork.

@@ -472,7 +472,7 @@ impl Values<'_> {
}
FromSqlError::OutOfRange(i) => Error::IntegralValueOutOfRange(idx, i),
#[cfg(feature = "i128_blob")]
FromSqlError::InvalidI128Size(_) => Error::InvalidColumnType(idx, value.data_type()),
FromSqlError::InvalidI128Size(_) => Error::InvalidColumnType(idx, idx.to_string(), value.data_type()),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's dodgy to do idx.to_string() here for the name, but I'm not sure it particualrly matters. I almost made the name an Option on the error type, but decided against since it should always be present outside of this case, which should be rare. I'd be willing to change it to do that again if it would be preferred though.

pub(crate) fn column_name(&self, col: usize) -> &str {
// Just panic if the bounds are wrong for now, we never call this
// without checking first.
let slice = self.stmt.column_name(col).expect("Column out of bounds");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expect is here instead of a panic inside the inner stmt's column_name mostly since I debated exposing this publicly, which would have had column_name return a Option<&str>. I can change that if you want.

@thomcc thomcc force-pushed the include-column-name-in-type-error branch from 8ca8ac8 to 4356f5a Compare June 25, 2019 19:20
@gwenn
Copy link
Collaborator

gwenn commented Jun 25, 2019

I will try to do a release tomorrow.
And I suggest you ask @jgallagher to grant you access.

@thomcc
Copy link
Member Author

thomcc commented Jun 25, 2019

And I suggest you ask @jgallagher to grant you access.

Ah sure, I will. I meant to the last time you suggested but forgot.

@thomcc thomcc merged commit 3aca84c into rusqlite:master Jun 26, 2019
@thomcc thomcc deleted the include-column-name-in-type-error branch June 26, 2019 16:38
@thomcc
Copy link
Member Author

thomcc commented Jun 26, 2019

Thanks a ton for cutting the release @gwenn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants