Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[rust][photos] Merge the ML DB string error variants

laurenspriem9128f795b0be
diff --git a/rust/bindings/frb/photos/src/api/ml_db_api.rs b/rust/bindings/frb/photos/src/api/ml_db_api.rs
index e7897f4ddc..3e430f47d9 100644
--- a/rust/bindings/frb/photos/src/api/ml_db_api.rs
+++ b/rust/bindings/frb/photos/src/api/ml_db_api.rs
@@ -866,7 +866,7 @@ mod tests {
#[test]
fn other_errors_keep_the_bridge_variant_and_message() {
- let error = MlDbError::from(ml_db::Error::InvalidArgument("invalid value".into()));
+ let error = MlDbError::from(ml_db::Error::Invalid("invalid value".into()));
assert!(matches!(
error,
MlDbError::Other { message } if message == "invalid value"
diff --git a/rust/crates/photos/src/ml_db/mod.rs b/rust/crates/photos/src/ml_db/mod.rs
index a365e579f5..ea72c2a8be 100644
--- a/rust/crates/photos/src/ml_db/mod.rs
+++ b/rust/crates/photos/src/ml_db/mod.rs
@@ -27,15 +27,11 @@ pub enum Error {
#[error("currentVersion({current}) cannot be greater than toVersion({target})")]
Downgrade { current: i64, target: i64 },
#[error("{0}")]
- Codec(String),
- #[error("{0}")]
- InvalidArgument(String),
+ Invalid(String),
}
pub type Result<T> = std::result::Result<T, Error>;
-pub const TARGET_VERSION: i64 = schema::MIGRATION_SCRIPTS.len() as i64;
-
pub struct MlDb {
db: Database,
}
@@ -89,7 +85,7 @@ mod tests {
use super::queries::clip::tests::full_clip;
use super::queries::{caches, clip, clusters, faces, filedata, persons, pets};
- use super::{Error, MlDb, TARGET_VERSION};
+ use super::{Error, MlDb, schema};
use crate::db::Connection;
use tempfile::TempDir;
@@ -281,7 +277,7 @@ mod tests {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("ente.ml.db");
let _db = MlDb::open(&path).unwrap();
- assert_eq!(TARGET_VERSION, 15);
+ assert_eq!(schema::MIGRATION_SCRIPTS.len(), 15);
assert_eq!(user_version(&path), 15);
let connection = Connection::open(&path).unwrap();
for table in [
diff --git a/rust/crates/photos/src/ml_db/queries/faces.rs b/rust/crates/photos/src/ml_db/queries/faces.rs
index 0e3897e1c4..174bcfccf2 100644
--- a/rust/crates/photos/src/ml_db/queries/faces.rs
+++ b/rust/crates/photos/src/ml_db/queries/faces.rs
@@ -233,7 +233,7 @@ impl MlDb {
}
}
if person_id.is_none() && cluster_id.is_none() {
- return Err(Error::InvalidArgument(
+ return Err(Error::Invalid(
"personID and clusterID cannot be null".to_string(),
));
}
@@ -560,7 +560,7 @@ pub(super) fn is_bad_face_for_clustering(
pub(super) fn file_id_from_face_id(face_id: &str) -> Result<i64> {
try_file_id_from_face_id(face_id)
- .ok_or_else(|| Error::Codec(format!("Error parsing faceId: {face_id}")))
+ .ok_or_else(|| Error::Invalid(format!("Error parsing faceId: {face_id}")))
}
fn try_file_id_from_face_id(face_id: &str) -> Option<i64> {
@@ -899,7 +899,7 @@ pub(in crate::ml_db) mod tests {
assert_eq!(cover(9, Some("p9"), None, None), None);
assert!(matches!(
db.get_cover_face_for_person(1, None, None, None),
- Err(Error::InvalidArgument(_))
+ Err(Error::Invalid(_))
));
}
diff --git a/rust/crates/photos/src/ml_db/vector_encoding.rs b/rust/crates/photos/src/ml_db/vector_encoding.rs
index 2bd743f3a5..8cb9ddff1b 100644
--- a/rust/crates/photos/src/ml_db/vector_encoding.rs
+++ b/rust/crates/photos/src/ml_db/vector_encoding.rs
@@ -145,7 +145,7 @@ fn advance(bytes: &[u8], offset: &mut usize, count: usize) -> Result<usize> {
}
fn malformed() -> Error {
- Error::Codec("malformed EVector bytes".to_string())
+ Error::Invalid("malformed EVector bytes".to_string())
}
#[cfg(test)]