Expose better error messages

This commit is contained in:
Clément Renault 2024-11-25 15:54:43 +01:00
parent dd76eaaaec
commit 25aac45fc7
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
3 changed files with 51 additions and 6 deletions

View File

@ -61,6 +61,10 @@ pub enum InternalError {
Serialization(#[from] SerializationError), Serialization(#[from] SerializationError),
#[error(transparent)] #[error(transparent)]
Store(#[from] MdbError), Store(#[from] MdbError),
#[error("Cannot delete {key:?} from database {database_name}: {error}")]
StoreDeletion { database_name: &'static str, key: Vec<u8>, error: heed::Error },
#[error("Cannot insert {key:?} and value with length {value_length} into database {database_name}: {error}")]
StorePut { database_name: &'static str, key: Vec<u8>, value_length: usize, error: heed::Error },
#[error(transparent)] #[error(transparent)]
Utf8(#[from] str::Utf8Error), Utf8(#[from] str::Utf8Error),
#[error("An indexation process was explicitly aborted")] #[error("An indexation process was explicitly aborted")]

View File

@ -11,7 +11,7 @@ use super::extract::FacetKind;
use super::StdResult; use super::StdResult;
use crate::heed_codec::facet::{FieldDocIdFacetF64Codec, FieldDocIdFacetStringCodec}; use crate::heed_codec::facet::{FieldDocIdFacetF64Codec, FieldDocIdFacetStringCodec};
use crate::index::main_key::{GEO_FACETED_DOCUMENTS_IDS_KEY, GEO_RTREE_KEY}; use crate::index::main_key::{GEO_FACETED_DOCUMENTS_IDS_KEY, GEO_RTREE_KEY};
use crate::index::IndexEmbeddingConfig; use crate::index::{db_name, IndexEmbeddingConfig};
use crate::update::new::KvReaderFieldId; use crate::update::new::KvReaderFieldId;
use crate::vector::Embedding; use crate::vector::Embedding;
use crate::{DocumentId, Index}; use crate::{DocumentId, Index};
@ -139,6 +139,27 @@ impl Database {
Database::FieldIdDocidFacetF64s => index.field_id_docid_facet_f64s.remap_types(), Database::FieldIdDocidFacetF64s => index.field_id_docid_facet_f64s.remap_types(),
} }
} }
pub fn database_name(&self) -> &'static str {
match self {
Database::Main => db_name::MAIN,
Database::Documents => db_name::DOCUMENTS,
Database::ExternalDocumentsIds => db_name::EXTERNAL_DOCUMENTS_IDS,
Database::ExactWordDocids => db_name::EXACT_WORD_DOCIDS,
Database::WordDocids => db_name::WORD_DOCIDS,
Database::WordFidDocids => db_name::WORD_FIELD_ID_DOCIDS,
Database::WordPositionDocids => db_name::WORD_POSITION_DOCIDS,
Database::FidWordCountDocids => db_name::FIELD_ID_WORD_COUNT_DOCIDS,
Database::WordPairProximityDocids => db_name::WORD_PAIR_PROXIMITY_DOCIDS,
Database::FacetIdIsNullDocids => db_name::FACET_ID_IS_NULL_DOCIDS,
Database::FacetIdIsEmptyDocids => db_name::FACET_ID_IS_EMPTY_DOCIDS,
Database::FacetIdExistsDocids => db_name::FACET_ID_EXISTS_DOCIDS,
Database::FacetIdF64NumberDocids => db_name::FACET_ID_F64_DOCIDS,
Database::FacetIdStringDocids => db_name::FACET_ID_STRING_DOCIDS,
Database::FieldIdDocidFacetStrings => db_name::FIELD_ID_DOCID_FACET_STRINGS,
Database::FieldIdDocidFacetF64s => db_name::FIELD_ID_DOCID_FACET_F64S,
}
}
} }
impl From<FacetKind> for Database { impl From<FacetKind> for Database {
@ -158,6 +179,10 @@ impl DbOperation {
self.database.database(index) self.database.database(index)
} }
pub fn database_name(&self) -> &'static str {
self.database.database_name()
}
pub fn entry(self) -> EntryOperation { pub fn entry(self) -> EntryOperation {
self.entry self.entry
} }

View File

@ -41,7 +41,7 @@ use crate::update::settings::InnerIndexSettings;
use crate::update::{FacetsUpdateBulk, GrenadParameters}; use crate::update::{FacetsUpdateBulk, GrenadParameters};
use crate::vector::{ArroyWrapper, EmbeddingConfigs, Embeddings}; use crate::vector::{ArroyWrapper, EmbeddingConfigs, Embeddings};
use crate::{ use crate::{
FieldsIdsMap, GlobalFieldsIdsMap, Index, InternalError, Result, ThreadPoolNoAbort, Error, FieldsIdsMap, GlobalFieldsIdsMap, Index, InternalError, Result, ThreadPoolNoAbort,
ThreadPoolNoAbortBuilder, UserError, ThreadPoolNoAbortBuilder, UserError,
}; };
@ -356,13 +356,29 @@ where
match operation { match operation {
WriterOperation::DbOperation(db_operation) => { WriterOperation::DbOperation(db_operation) => {
let database = db_operation.database(index); let database = db_operation.database(index);
let database_name = db_operation.database_name();
match db_operation.entry() { match db_operation.entry() {
EntryOperation::Delete(e) => { EntryOperation::Delete(e) => match database.delete(wtxn, e.entry()) {
if !database.delete(wtxn, e.entry())? { Ok(false) => unreachable!("We tried to delete an unknown key"),
unreachable!("We tried to delete an unknown key") Ok(_) => (),
Err(error) => {
return Err(Error::InternalError(InternalError::StoreDeletion {
database_name,
key: e.entry().to_owned(),
error,
}));
}
},
EntryOperation::Write(e) => {
if let Err(error) = database.put(wtxn, e.key(), e.value()) {
return Err(Error::InternalError(InternalError::StorePut {
database_name,
key: e.key().to_owned(),
value_length: e.value().len(),
error,
}));
} }
} }
EntryOperation::Write(e) => database.put(wtxn, e.key(), e.value())?,
} }
} }
WriterOperation::ArroyOperation(arroy_operation) => match arroy_operation { WriterOperation::ArroyOperation(arroy_operation) => match arroy_operation {