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 (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 mut field_map: HashMap<_, _> = schema
|
||||
@ -81,7 +81,8 @@ impl TantivyBackend {
|
||||
let schema = schema_builder.build();
|
||||
|
||||
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)
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use colour::{dark_grey_ln, grey_ln, yellow_ln};
|
||||
use colour::{dark_grey_ln, yellow_ln};
|
||||
use env_logger::Env;
|
||||
|
||||
use quickpeep_indexer::config::IndexerConfig;
|
||||
|
@ -44,9 +44,12 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
.unwrap_or_else(|| PathBuf::from("quickpeep.ron"));
|
||||
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 handle = tokio::spawn(async move {
|
||||
seed_loader(seed_files, &seed_tx).await?;
|
||||
@ -73,13 +76,15 @@ pub async fn main() -> anyhow::Result<()> {
|
||||
SCHEMA_RAKED_PAGES => {
|
||||
// TODO(unstable): this condition is `.has_data_left()` but it's unstable.
|
||||
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 => {
|
||||
// TODO(unstable): this condition is `.has_data_left()` but it's unstable.
|
||||
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,15 +148,17 @@ pub fn handle_page_pack(
|
||||
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);
|
||||
|
||||
indexer_backend.add_document(BackendIndependentDocument {
|
||||
title: document.head.title,
|
||||
article_body,
|
||||
nonarticle_body,
|
||||
// TODO populate tags & antifeatures
|
||||
tags,
|
||||
url: page_record.url.to_string(),
|
||||
favicon_url_hash,
|
||||
})?;
|
||||
indexer_backend
|
||||
.add_document(BackendIndependentDocument {
|
||||
title: document.head.title,
|
||||
article_body,
|
||||
nonarticle_body,
|
||||
// TODO populate tags & antifeatures
|
||||
tags,
|
||||
url: page_record.url.to_string(),
|
||||
favicon_url_hash,
|
||||
})
|
||||
.context("failed to add document to indexer backend")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -46,9 +46,10 @@ impl IndexerConfig {
|
||||
|
||||
pub fn open_indexer_backend(&self) -> anyhow::Result<Box<dyn Backend>> {
|
||||
match &self.index.backend {
|
||||
BackendConfig::Tantivy(tantivy) => {
|
||||
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
|
||||
}
|
||||
BackendConfig::Tantivy(tantivy) => Ok(Box::new(
|
||||
TantivyBackend::open(&tantivy.index_dir)
|
||||
.context("failed to open Tantivy backend")?,
|
||||
)),
|
||||
BackendConfig::Meili(_) => {
|
||||
todo!()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user