mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-28 10:29:30 +02:00
chore: removed anyhow from apperror for improved error handling
This commit is contained in:
+3
-3
@@ -26,12 +26,12 @@ pub enum AppError {
|
|||||||
Join(#[from] JoinError),
|
Join(#[from] JoinError),
|
||||||
#[error("Graph mapper error: {0}")]
|
#[error("Graph mapper error: {0}")]
|
||||||
GraphMapper(String),
|
GraphMapper(String),
|
||||||
#[error("IoError: {0}")]
|
#[error("IO error: {0}")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
#[error("Reqwest error: {0}")]
|
#[error("Reqwest error: {0}")]
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
#[error("Anyhow error: {0}")]
|
#[error("Storage error: {0}")]
|
||||||
Anyhow(#[from] anyhow::Error),
|
Storage(#[from] object_store::Error),
|
||||||
#[error("Ingestion Processing error: {0}")]
|
#[error("Ingestion Processing error: {0}")]
|
||||||
Processing(String),
|
Processing(String),
|
||||||
#[error("DOM smoothie error: {0}")]
|
#[error("DOM smoothie error: {0}")]
|
||||||
|
|||||||
@@ -253,11 +253,11 @@ impl FileInfo {
|
|||||||
|
|
||||||
// Remove the object's parent prefix in the object store
|
// Remove the object's parent prefix in the object store
|
||||||
let (parent_prefix, _file_name) = store::split_object_path(&file_info.path)
|
let (parent_prefix, _file_name) = store::split_object_path(&file_info.path)
|
||||||
.map_err(|e| AppError::from(anyhow::anyhow!(e)))?;
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
storage
|
storage
|
||||||
.delete_prefix(&parent_prefix)
|
.delete_prefix(&parent_prefix)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| AppError::from(anyhow::anyhow!(e)))?;
|
.map_err(AppError::Storage)?;
|
||||||
info!(
|
info!(
|
||||||
"Removed object prefix {} and its contents via StorageManager",
|
"Removed object prefix {} and its contents via StorageManager",
|
||||||
parent_prefix
|
parent_prefix
|
||||||
@@ -283,7 +283,7 @@ impl FileInfo {
|
|||||||
storage
|
storage
|
||||||
.get(&self.path)
|
.get(&self.path)
|
||||||
.await
|
.await
|
||||||
.map_err(|e: object_store::Error| AppError::from(anyhow::anyhow!(e)))
|
.map_err(AppError::Storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Persist file to storage using StorageManager.
|
/// Persist file to storage using StorageManager.
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ pub async fn generate_embedding_with_provider(
|
|||||||
provider: &EmbeddingProvider,
|
provider: &EmbeddingProvider,
|
||||||
input: &str,
|
input: &str,
|
||||||
) -> Result<Vec<f32>, AppError> {
|
) -> Result<Vec<f32>, AppError> {
|
||||||
provider.embed(input).await.map_err(AppError::from)
|
provider.embed(input).await.map_err(|e| AppError::InternalError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates an embedding vector for the given input text using `OpenAI`'s embedding model.
|
/// Generates an embedding vector for the given input text using `OpenAI`'s embedding model.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use chrono::Utc;
|
|||||||
use futures::stream::{self, StreamExt, TryStreamExt};
|
use futures::stream::{self, StreamExt, TryStreamExt};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use common::{
|
use common::{
|
||||||
error::AppError,
|
error::AppError,
|
||||||
storage::{
|
storage::{
|
||||||
@@ -161,7 +161,7 @@ async fn create_single_entity(
|
|||||||
provider
|
provider
|
||||||
.embed(&embedding_input)
|
.embed(&embedding_input)
|
||||||
.await
|
.await
|
||||||
.context("generating FastEmbed embedding for entity")?
|
.map_err(|e| AppError::InternalError(format!("FastEmbed embedding for entity failed: {e}")))?
|
||||||
} else {
|
} else {
|
||||||
generate_embedding(openai_client, &embedding_input, db_client).await?
|
generate_embedding(openai_client, &embedding_input, db_client).await?
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{
|
|||||||
sync::{Arc, OnceLock},
|
sync::{Arc, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use async_openai::types::{
|
use async_openai::types::{
|
||||||
ChatCompletionRequestSystemMessage, ChatCompletionRequestUserMessage,
|
ChatCompletionRequestSystemMessage, ChatCompletionRequestUserMessage,
|
||||||
CreateChatCompletionRequest, CreateChatCompletionRequestArgs, ResponseFormat,
|
CreateChatCompletionRequest, CreateChatCompletionRequestArgs, ResponseFormat,
|
||||||
@@ -269,7 +269,7 @@ impl PipelineServices for DefaultPipelineServices {
|
|||||||
.embedding_provider
|
.embedding_provider
|
||||||
.embed(&chunk_text)
|
.embed(&chunk_text)
|
||||||
.await
|
.await
|
||||||
.context("generating FastEmbed embedding for chunk")?;
|
.map_err(|e| AppError::InternalError(format!("FastEmbed embedding for chunk failed: {e}")))?;
|
||||||
let chunk_struct = TextChunk::new(
|
let chunk_struct = TextChunk::new(
|
||||||
content.get_id().to_string(),
|
content.get_id().to_string(),
|
||||||
chunk_text,
|
chunk_text,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use anyhow::anyhow;
|
|
||||||
use common::{
|
use common::{
|
||||||
error::AppError,
|
error::AppError,
|
||||||
storage::{db::SurrealDbClient, store::StorageManager, types::file_info::FileInfo},
|
storage::{db::SurrealDbClient, store::StorageManager, types::file_info::FileInfo},
|
||||||
@@ -78,7 +77,7 @@ pub async fn extract_text_from_file(
|
|||||||
let file_bytes = storage
|
let file_bytes = storage
|
||||||
.get(&file_info.path)
|
.get(&file_info.path)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| AppError::from(anyhow!(e)))?;
|
.map_err(AppError::Storage)?;
|
||||||
let local_path = resolve_existing_local_path(storage, &file_info.path).await;
|
let local_path = resolve_existing_local_path(storage, &file_info.path).await;
|
||||||
|
|
||||||
match file_info.mime_type.as_str() {
|
match file_info.mime_type.as_str() {
|
||||||
|
|||||||
@@ -30,24 +30,36 @@ pub async fn extract_text_from_url(
|
|||||||
.sandbox(false)
|
.sandbox(false)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
Browser::new(options)?
|
Browser::new(options)
|
||||||
|
.map_err(|e| AppError::InternalError(e.to_string()))?
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "docker"))]
|
#[cfg(not(feature = "docker"))]
|
||||||
{
|
{
|
||||||
Browser::default()?
|
Browser::default()
|
||||||
|
.map_err(|e| AppError::InternalError(e.to_string()))?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let tab = browser.new_tab()?;
|
let tab = browser
|
||||||
let page = tab.navigate_to(url)?;
|
.new_tab()
|
||||||
let loaded_page = page.wait_until_navigated()?;
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
let raw_content = loaded_page.get_content()?;
|
let page = tab
|
||||||
let screenshot = loaded_page.capture_screenshot(
|
.navigate_to(url)
|
||||||
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
|
let loaded_page = page
|
||||||
|
.wait_until_navigated()
|
||||||
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
|
let raw_content = loaded_page
|
||||||
|
.get_content()
|
||||||
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
|
let screenshot = loaded_page
|
||||||
|
.capture_screenshot(
|
||||||
headless_chrome::protocol::cdp::Page::CaptureScreenshotFormatOption::Jpeg,
|
headless_chrome::protocol::cdp::Page::CaptureScreenshotFormatOption::Jpeg,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
true,
|
true,
|
||||||
)?;
|
)
|
||||||
|
.map_err(|e| AppError::InternalError(e.to_string()))?;
|
||||||
|
|
||||||
let mut tmp_file = NamedTempFile::new()?;
|
let mut tmp_file = NamedTempFile::new()?;
|
||||||
let temp_path_str = tmp_file.path().display().to_string();
|
let temp_path_str = tmp_file.path().display().to_string();
|
||||||
|
|||||||
Reference in New Issue
Block a user