mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
reintroduce anyhow
This commit is contained in:
parent
439db1aae0
commit
02277ec2cf
36 changed files with 110 additions and 154 deletions
|
@ -3,6 +3,7 @@ use std::io::{BufRead, BufReader, Write};
|
|||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use heed::RoTxn;
|
||||
use indexmap::IndexMap;
|
||||
use milli::update::{IndexDocumentsMethod, UpdateFormat::JsonStream};
|
||||
|
@ -10,8 +11,8 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::option::IndexerOpts;
|
||||
|
||||
use super::{update_handler::UpdateHandler, Index, Settings, Unchecked};
|
||||
use super::error::{IndexError, Result};
|
||||
use super::{update_handler::UpdateHandler, Index, Settings, Unchecked};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct DumpMeta {
|
||||
|
@ -37,7 +38,8 @@ impl Index {
|
|||
let document_file_path = path.as_ref().join(DATA_FILE_NAME);
|
||||
let mut document_file = File::create(&document_file_path)?;
|
||||
|
||||
let documents = self.all_documents(txn)
|
||||
let documents = self
|
||||
.all_documents(txn)
|
||||
.map_err(|e| IndexError::Internal(e.into()))?;
|
||||
let fields_ids_map = self.fields_ids_map(txn)?;
|
||||
|
||||
|
@ -82,13 +84,12 @@ impl Index {
|
|||
dst: impl AsRef<Path>,
|
||||
size: usize,
|
||||
indexing_options: &IndexerOpts,
|
||||
) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
) -> anyhow::Result<()> {
|
||||
let dir_name = src
|
||||
.as_ref()
|
||||
.file_name()
|
||||
// TODO: remove
|
||||
//.with_context(|| format!("invalid dump index: {}", src.as_ref().display()))?;
|
||||
.unwrap();
|
||||
.with_context(|| format!("invalid dump index: {}", src.as_ref().display()))?;
|
||||
|
||||
let dst_dir_path = dst.as_ref().join("indexes").join(dir_name);
|
||||
create_dir_all(&dst_dir_path)?;
|
||||
|
||||
|
|
|
@ -27,12 +27,7 @@ macro_rules! internal_error {
|
|||
}
|
||||
}
|
||||
|
||||
internal_error!(
|
||||
std::io::Error,
|
||||
heed::Error,
|
||||
fst::Error,
|
||||
serde_json::Error
|
||||
);
|
||||
internal_error!(std::io::Error, heed::Error, fst::Error, serde_json::Error);
|
||||
|
||||
impl ErrorCode for IndexError {
|
||||
fn error_code(&self) -> Code {
|
||||
|
@ -47,14 +42,13 @@ impl ErrorCode for IndexError {
|
|||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum FacetError {
|
||||
#[error("Invalid facet expression, expected {}, found: {1}", .0.join(", "))]
|
||||
InvalidExpression(&'static [&'static str], Value)
|
||||
InvalidExpression(&'static [&'static str], Value),
|
||||
}
|
||||
|
||||
impl ErrorCode for FacetError {
|
||||
impl ErrorCode for FacetError {
|
||||
fn error_code(&self) -> Code {
|
||||
match self {
|
||||
FacetError::InvalidExpression(_, _) => Code::Facet,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ pub struct UpdateHandler {
|
|||
}
|
||||
|
||||
impl UpdateHandler {
|
||||
pub fn new(opt: &IndexerOpts) -> std::result::Result<Self, Box<dyn std::error::Error>> {
|
||||
pub fn new(opt: &IndexerOpts) -> anyhow::Result<Self> {
|
||||
let thread_pool = rayon::ThreadPoolBuilder::new()
|
||||
.num_threads(opt.indexing_jobs.unwrap_or(0))
|
||||
.build()?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::{BTreeSet, BTreeMap, HashSet};
|
||||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||
use std::io;
|
||||
use std::marker::PhantomData;
|
||||
use std::num::NonZeroUsize;
|
||||
|
@ -308,10 +308,9 @@ impl Index {
|
|||
}
|
||||
}
|
||||
|
||||
builder.execute(|indexing_step, update_id| {
|
||||
info!("update {}: {:?}", update_id, indexing_step)
|
||||
})
|
||||
.map_err(|e| IndexError::Internal(e.into()))?;
|
||||
builder
|
||||
.execute(|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step))
|
||||
.map_err(|e| IndexError::Internal(e.into()))?;
|
||||
|
||||
Ok(UpdateResult::Other)
|
||||
}
|
||||
|
@ -333,7 +332,8 @@ impl Index {
|
|||
update_builder: UpdateBuilder,
|
||||
) -> Result<UpdateResult> {
|
||||
let mut txn = self.write_txn()?;
|
||||
let mut builder = update_builder.delete_documents(&mut txn, self)
|
||||
let mut builder = update_builder
|
||||
.delete_documents(&mut txn, self)
|
||||
.map_err(|e| IndexError::Internal(e.into()))?;
|
||||
|
||||
// We ignore unexisting document ids
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue