Implementation:0xranx OpenContext Search Error
| Knowledge Sources | |
|---|---|
| Domains | Search, Error_Handling |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Error type definitions for the search module, providing structured error variants and a result alias for all search operations in the Rust core library.
Description
The SearchError enum in crates/opencontext-core/src/search/error.rs defines all error categories that can occur during search operations: configuration errors, embedding API failures, vector store issues, index problems, IO/HTTP/JSON errors, LanceDB errors, and sentinel cases like IndexNotBuilt and ApiKeyMissing. It uses thiserror for ergonomic derive-based error definitions with #[from] automatic conversions for std::io::Error, reqwest::Error, serde_json::Error, and lancedb::Error.
Usage
Import these types in Rust search modules to return structured errors from search, indexing, and embedding operations. The SearchResult<T> alias simplifies function signatures.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: crates/opencontext-core/src/search/error.rs
- Lines: 1-45
Signature
#[derive(Debug, Error)]
pub enum SearchError {
Config(String),
Embedding(String),
VectorStore(String),
Index(String),
Search(String),
Io(#[from] std::io::Error),
Http(#[from] reqwest::Error),
Json(#[from] serde_json::Error),
Lance(#[from] lancedb::Error),
IndexNotBuilt,
ApiKeyMissing,
}
pub type SearchResult<T> = std::result::Result<T, SearchError>;
Import
use opencontext_core::search::error::{SearchError, SearchResult};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| source error | std::io::Error / reqwest::Error / serde_json::Error / lancedb::Error | No | Auto-converted via #[from] |
| message | String | Yes (for String variants) | Human-readable error description |
Outputs
| Name | Type | Description |
|---|---|---|
| SearchError | enum | Structured error variant |
| SearchResult<T> | Result<T, SearchError> | Result alias for search operations |
Usage Examples
Returning Errors from Search Functions
use opencontext_core::search::error::{SearchError, SearchResult};
fn check_api_key(key: Option<&str>) -> SearchResult<()> {
match key {
Some(k) if !k.is_empty() => Ok(()),
_ => Err(SearchError::ApiKeyMissing),
}
}
// Auto-conversion from io::Error
fn read_config(path: &str) -> SearchResult<String> {
let content = std::fs::read_to_string(path)?; // io::Error auto-converts
Ok(content)
}
Matching on Error Variants
use opencontext_core::search::error::SearchError;
match result {
Err(SearchError::IndexNotBuilt) => println!("Run 'oc index build' first"),
Err(SearchError::ApiKeyMissing) => println!("Set OPENAI_API_KEY"),
Err(SearchError::Embedding(msg)) => println!("Embedding error: {}", msg),
Ok(results) => { /* ... */ }
}