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

Improve VersionMismatch error message #1422

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion libsqlite3-sys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ pub fn code_to_str(code: c_int) -> &'static str {
}
}

/// Formats SQLite version integer as parts
#[cfg(feature = "loadable_extension")]
struct FmtVersion(i32);
#[cfg(feature = "loadable_extension")]
impl ::std::fmt::Display for FmtVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"v{}.{}.{}",
self.0 / 1000000,
(self.0 / 1000) % 1000,
self.0 % 1000
)
}
}

/// Loadable extension initialization error
#[cfg(feature = "loadable_extension")]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand All @@ -292,7 +308,12 @@ impl ::std::fmt::Display for InitError {
compile_time,
runtime,
} => {
write!(f, "SQLite version mismatch: {runtime} < {compile_time}")
write!(
f,
"SQLite version mismatch: runtime {} < compiled {}",
FmtVersion(runtime),
FmtVersion(compile_time)
)
}
InitError::NullFunctionPointer => {
write!(f, "Some sqlite3_api_routines fields are null")
Expand Down