mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
Do not leak an internal grenad Error
This commit is contained in:
parent
8ebf5eed0d
commit
dc3f092d07
@ -7,7 +7,7 @@ use std::io;
|
||||
use bimap::BiHashMap;
|
||||
pub use builder::DocumentsBatchBuilder;
|
||||
use obkv::KvReader;
|
||||
pub use reader::{DocumentsBatchCursor, DocumentsBatchReader};
|
||||
pub use reader::{DocumentsBatchCursor, DocumentsBatchCursorError, DocumentsBatchReader};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::{FieldIdMapMissingEntry, InternalError};
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::convert::TryInto;
|
||||
use std::io;
|
||||
use std::{error, fmt, io};
|
||||
|
||||
use obkv::KvReader;
|
||||
|
||||
@ -79,7 +79,9 @@ impl<R> DocumentsBatchCursor<R> {
|
||||
impl<R: io::Read + io::Seek> DocumentsBatchCursor<R> {
|
||||
/// Returns the next document, starting from the first one. Subsequent calls to
|
||||
/// `next_document` advance the document reader until all the documents have been read.
|
||||
pub fn next_document(&mut self) -> Result<Option<KvReader<FieldId>>, grenad::Error> {
|
||||
pub fn next_document(
|
||||
&mut self,
|
||||
) -> Result<Option<KvReader<FieldId>>, DocumentsBatchCursorError> {
|
||||
match self.cursor.move_on_next()? {
|
||||
Some((key, value)) if key != DOCUMENTS_BATCH_INDEX_KEY => {
|
||||
Ok(Some(KvReader::new(value)))
|
||||
@ -88,3 +90,29 @@ impl<R: io::Read + io::Seek> DocumentsBatchCursor<R> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The possible error thrown by the `DocumentsBatchCursor` when iterating on the documents.
|
||||
#[derive(Debug)]
|
||||
pub struct DocumentsBatchCursorError {
|
||||
inner: grenad::Error,
|
||||
}
|
||||
|
||||
impl From<grenad::Error> for DocumentsBatchCursorError {
|
||||
fn from(error: grenad::Error) -> DocumentsBatchCursorError {
|
||||
DocumentsBatchCursorError { inner: error }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<grenad::Error> for DocumentsBatchCursorError {
|
||||
fn into(self) -> grenad::Error {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for DocumentsBatchCursorError {}
|
||||
|
||||
impl fmt::Display for DocumentsBatchCursorError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(f)
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use rayon::ThreadPoolBuildError;
|
||||
use serde_json::Value;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::documents::DocumentsBatchCursorError;
|
||||
use crate::{CriterionError, DocumentId, FieldId, Object, SortError};
|
||||
|
||||
pub fn is_reserved_keyword(keyword: &str) -> bool {
|
||||
@ -209,6 +210,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DocumentsBatchCursorError> for Error {
|
||||
fn from(error: DocumentsBatchCursorError) -> Error {
|
||||
Error::from(Into::<grenad::Error>::into(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Infallible> for Error {
|
||||
fn from(_error: Infallible) -> Error {
|
||||
unreachable!()
|
||||
|
Loading…
Reference in New Issue
Block a user