janhq/jan · error · RagError
ParseError
ParseError
Error message
Failed to parse document: {0} What it means
RagError::ParseError is raised when the RAG plugin fails to parse a document's contents (displayed as "Failed to parse document: {0}" with the underlying reason). Document ingestion (PDF, text, etc.) must yield readable text before chunking/embedding; unparsable or damaged files abort the pipeline with this error.
Solutions
- Read the wrapped message to see which parser stage failed.
- Verify the file opens correctly in its native application; re-export or repair if not.
- Convert problematic documents (e.g. re-save the PDF, normalize to UTF-8 text) before ingestion.
- For image-only PDFs, run OCR first or reject the file with a friendly user message.
Example fix
// before
rag.ingest(path).unwrap();
// after
match rag.ingest(path) {
Err(RagError::ParseError(msg)) => {
eprintln!("Skipping {path:?}: not a readable document ({msg})");
}
other => other.expect("ingest failed"),
} Defensive patterns
Strategy: validation
Validate before calling
// Rust: pre-check file readability before RAG ingestion
fn looks_parseable(path: &Path) -> bool {
std::fs::read(path).map(|bytes| !bytes.is_empty() && !bytes.starts_with(&[0u8; 4][..])).unwrap_or(false)
} Type guard
fn as_parse_error(err: &RagError) -> Option<&str> {
match err { RagError::ParseError(m) => Some(m), _ => None }
} Try / catch
match rag.ingest(doc) {
Err(RagError::ParseError(msg)) => {
notify_user(format!("Could not read document: {msg}"));
}
other => other?,
} Prevention
- Validate files open in their native format before ingestion.
- Run OCR on image-only PDFs before indexing.
- Normalize text encodings to UTF-8 during upload.
- Quarantine files that repeatedly fail parsing for user review.
When it happens
Trigger: Ingesting a file into the RAG index whose contents can't be decoded — corrupted PDFs, password-protected documents, binary files mislabeled as text, or encoding failures.
Common situations: Uploading scanned/image-only PDFs without an OCR layer; files with wrong extensions; documents saved with unexpected encodings; truncated uploads.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17).
Data as JSON: /api/errors/38b51a23578533dd.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/plugins/tauri-plugin-rag/src/error.rs:5
use serde::{Deserialize, Serialize};
#[derive(Debug, thiserror::Error, Serialize, Deserialize)]
pub enum RagError {
#[error("Failed to parse document: {0}")]
ParseError(String),
#[error("Unsupported file type: {0}")]
UnsupportedFileType(String),
#[error("IO error: {0}")]
IoError(String),
}
impl From<std::io::Error> for RagError {
fn from(err: std::io::Error) -> Self {
RagError::IoError(err.to_string())
}
}
View on GitHub (pinned to 7205d770c1)