Add more context to error messages
This commit is contained in:
parent
117b608ab0
commit
e1dcd73423
@ -50,7 +50,7 @@ impl TantivyBackend {
|
|||||||
let dir_path = path.join("tantivy");
|
let dir_path = path.join("tantivy");
|
||||||
|
|
||||||
let (index, fields) = if dir_path.exists() {
|
let (index, fields) = if dir_path.exists() {
|
||||||
let index = Index::open_in_dir(&dir_path)?;
|
let index = Index::open_in_dir(&dir_path).context("failed to open index")?;
|
||||||
|
|
||||||
let schema = index.schema();
|
let schema = index.schema();
|
||||||
let mut field_map: HashMap<_, _> = schema
|
let mut field_map: HashMap<_, _> = schema
|
||||||
@ -81,7 +81,8 @@ impl TantivyBackend {
|
|||||||
let schema = schema_builder.build();
|
let schema = schema_builder.build();
|
||||||
|
|
||||||
std::fs::create_dir(&dir_path)?;
|
std::fs::create_dir(&dir_path)?;
|
||||||
let index = Index::create_in_dir(&dir_path, schema)?;
|
let index =
|
||||||
|
Index::create_in_dir(&dir_path, schema).context("failed to create index")?;
|
||||||
|
|
||||||
(index, fields)
|
(index, fields)
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use colour::{dark_grey_ln, grey_ln, yellow_ln};
|
use colour::{dark_grey_ln, yellow_ln};
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
|
|
||||||
use quickpeep_indexer::config::IndexerConfig;
|
use quickpeep_indexer::config::IndexerConfig;
|
||||||
|
@ -44,9 +44,12 @@ pub async fn main() -> anyhow::Result<()> {
|
|||||||
.unwrap_or_else(|| PathBuf::from("quickpeep.ron"));
|
.unwrap_or_else(|| PathBuf::from("quickpeep.ron"));
|
||||||
let config = IndexerConfig::load(&config_path).context("Failed to load config")?;
|
let config = IndexerConfig::load(&config_path).context("Failed to load config")?;
|
||||||
|
|
||||||
let icon_store = IconStore::open(config.index.icon_store.as_path())?;
|
let icon_store =
|
||||||
|
IconStore::open(config.index.icon_store.as_path()).context("failed to open icon store")?;
|
||||||
|
|
||||||
let seed_files = find_seed_files(config.seed_dir.clone(), SEED_EXTENSION).await?;
|
let seed_files = find_seed_files(config.seed_dir.clone(), SEED_EXTENSION)
|
||||||
|
.await
|
||||||
|
.context("failed to find seed files")?;
|
||||||
let (seed_tx, seed_rx) = tokio::sync::mpsc::channel(64);
|
let (seed_tx, seed_rx) = tokio::sync::mpsc::channel(64);
|
||||||
let handle = tokio::spawn(async move {
|
let handle = tokio::spawn(async move {
|
||||||
seed_loader(seed_files, &seed_tx).await?;
|
seed_loader(seed_files, &seed_tx).await?;
|
||||||
@ -73,13 +76,15 @@ pub async fn main() -> anyhow::Result<()> {
|
|||||||
SCHEMA_RAKED_PAGES => {
|
SCHEMA_RAKED_PAGES => {
|
||||||
// TODO(unstable): this condition is `.has_data_left()` but it's unstable.
|
// TODO(unstable): this condition is `.has_data_left()` but it's unstable.
|
||||||
while buf_reader.fill_buf().map(|b| !b.is_empty())? {
|
while buf_reader.fill_buf().map(|b| !b.is_empty())? {
|
||||||
handle_page_pack(&mut buf_reader, &seed_lookup, &mut indexer_backend)?;
|
handle_page_pack(&mut buf_reader, &seed_lookup, &mut indexer_backend)
|
||||||
|
.context("failed to handle page pack")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SCHEMA_RAKED_ICONS => {
|
SCHEMA_RAKED_ICONS => {
|
||||||
// TODO(unstable): this condition is `.has_data_left()` but it's unstable.
|
// TODO(unstable): this condition is `.has_data_left()` but it's unstable.
|
||||||
while buf_reader.fill_buf().map(|b| !b.is_empty())? {
|
while buf_reader.fill_buf().map(|b| !b.is_empty())? {
|
||||||
handle_icon_pack(&mut buf_reader, &icon_store)?;
|
handle_icon_pack(&mut buf_reader, &icon_store)
|
||||||
|
.context("failed to handle icon pack")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -143,7 +148,8 @@ pub fn handle_page_pack(
|
|||||||
favicon_url_hash_long.copy_from_slice(&blake3::hash(favicon_url.as_bytes()).as_bytes()[0..8]);
|
favicon_url_hash_long.copy_from_slice(&blake3::hash(favicon_url.as_bytes()).as_bytes()[0..8]);
|
||||||
let favicon_url_hash = u64::from_le_bytes(favicon_url_hash_long);
|
let favicon_url_hash = u64::from_le_bytes(favicon_url_hash_long);
|
||||||
|
|
||||||
indexer_backend.add_document(BackendIndependentDocument {
|
indexer_backend
|
||||||
|
.add_document(BackendIndependentDocument {
|
||||||
title: document.head.title,
|
title: document.head.title,
|
||||||
article_body,
|
article_body,
|
||||||
nonarticle_body,
|
nonarticle_body,
|
||||||
@ -151,7 +157,8 @@ pub fn handle_page_pack(
|
|||||||
tags,
|
tags,
|
||||||
url: page_record.url.to_string(),
|
url: page_record.url.to_string(),
|
||||||
favicon_url_hash,
|
favicon_url_hash,
|
||||||
})?;
|
})
|
||||||
|
.context("failed to add document to indexer backend")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,10 @@ impl IndexerConfig {
|
|||||||
|
|
||||||
pub fn open_indexer_backend(&self) -> anyhow::Result<Box<dyn Backend>> {
|
pub fn open_indexer_backend(&self) -> anyhow::Result<Box<dyn Backend>> {
|
||||||
match &self.index.backend {
|
match &self.index.backend {
|
||||||
BackendConfig::Tantivy(tantivy) => {
|
BackendConfig::Tantivy(tantivy) => Ok(Box::new(
|
||||||
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
|
TantivyBackend::open(&tantivy.index_dir)
|
||||||
}
|
.context("failed to open Tantivy backend")?,
|
||||||
|
)),
|
||||||
BackendConfig::Meili(_) => {
|
BackendConfig::Meili(_) => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user