{"record":{"id":"3b4cfab4a42aad7c","repo":"janhq/jan","slug":"invalid-input-0","errorCode":null,"errorMessage":"Invalid input: {0}","messagePattern":"Invalid input: (.+?)","errorType":"exception","errorClass":"VectorDBError","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-vector-db/src/error.rs","lineNumber":8,"sourceCode":"use serde::{Deserialize, Serialize};\n\n#[derive(Debug, thiserror::Error, Serialize, Deserialize)]\npub enum VectorDBError {\n    #[error(\"Database error: {0}\")]\n    DatabaseError(String),\n\n    #[error(\"Invalid input: {0}\")]\n    InvalidInput(String),\n}\n\nimpl From<rusqlite::Error> for VectorDBError {\n    fn from(err: rusqlite::Error) -> Self {\n        VectorDBError::DatabaseError(err.to_string())\n    }\n}\n\nimpl From<serde_json::Error> for VectorDBError {\n    fn from(err: serde_json::Error) -> Self {\n        VectorDBError::DatabaseError(err.to_string())\n    }\n}\n\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/src-tauri/plugins/tauri-plugin-vector-db/src/error.rs#L1-L24","documentation":"The InvalidInput variant of VectorDBError is thrown when a caller passes data that fails pre-execution validation (e.g. wrong vector dimensionality, empty collection name, malformed IDs) before any SQL is run. It is a manual variant — unlike DatabaseError which auto-converts from rusqlite::Error and serde_json::Error via From impls, InvalidInput must be explicitly constructed by command code. The {0} placeholder is the human-readable detail string supplied at construction time.","triggerScenarios":"Calling vector-db insert/upsert/search commands with a vector whose dimension count does not match the collection's configured dimension. Passing an empty or whitespace-only collection name. Supplying a vector ID that is not a valid string or integer. Providing a filter/metadata payload that fails schema validation.","commonSituations":"Switching embedding models without recreating the collection (384-dim model into a 1536-dim collection). Copy-pasting a dimension from a different provider's docs. Frontend sending a stale/null ID after a race condition. Version mismatch between the plugin and the embedding backend.","solutions":["Check the collection's dimension before inserting and ensure the incoming vector length matches it exactly.","Validate collection names are non-empty alphanumeric strings before calling the API.","Log the full error string {0} — it contains the specific field and expected value.","Recreate the collection with the correct dimension if the embedding model changed."],"exampleFix":"// before\nstore.insert(\"docs\", vec![0.1, 0.2]).await?; // dim mismatch if collection is 1536\n\n// after\nlet dim = store.collection_dimension(\"docs\").await?;\nif embedding.len() != dim {\n    return Err(VectorDBError::InvalidInput(format!(\n        \"vector dim {} != collection dim {}\", embedding.len(), dim\n    )));\n}\nstore.insert(\"docs\", embedding).await?;","handlingStrategy":"validation","validationCode":"// Before calling vector-db insert/search, validate dimensions\nfunction validateVector(vector: number[], expectedDim: number): string | null {\n  if (!Array.isArray(vector) || vector.length === 0) return 'vector is empty';\n  if (vector.length !== expectedDim) return `dim ${vector.length} != expected ${expectedDim}`;\n  if (vector.some(v => typeof v !== 'number' || Number.isNaN(v))) return 'vector contains non-numeric values';\n  return null;\n}\n\nconst err = validateVector(embedding, collectionDim);\nif (err) { toast.error(`Invalid input: ${err}`); return; }","typeGuard":"function isValidVectorInput(v: unknown, dim: number): v is number[] {\n  return Array.isArray(v) && v.length === dim && v.every(x => typeof x === 'number' && !Number.isNaN(x));\n}\n\nfunction isValidCollectionName(name: string): boolean {\n  return /^[a-zA-Z0-9_-]{1,128}$/.test(name);\n}","tryCatchPattern":"match result {\n    Ok(data) => /* use data */,\n    Err(VectorDBError::InvalidInput(msg)) => {\n        log::warn!(\"Validation rejected: {msg}\");\n        // surface to user as a 400-style error\n    }\n    Err(VectorDBError::DatabaseError(msg)) => {\n        log::error!(\"DB error: {msg}\");\n        // surface as 500-style error\n    }\n}","preventionTips":["Always validate vector dimensionality against the collection schema before insert.","Sanitize collection names to alphanumeric + underscore/hyphen.","Write integration tests that exercise the dimension-mismatch path.","Log the expected vs actual dimension in the InvalidInput message."],"tags":["validation","vector-db","dimension-mismatch","input"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}