Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext Search Error

From Leeroopedia
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

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) => { /* ... */ }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment