{"record":{"id":"4c80c66e8db05645","repo":"janhq/jan","slug":"llamacpperror-code-code-message-messag","errorCode":null,"errorMessage":"LlamacppError {{ code: {code:?}, message: \"{message}\" }}","messagePattern":"LlamacppError (.+?), message: \"(.+?)\" \\}\\}","errorType":"error_code","errorClass":"LlamacppError","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/error.rs","lineNumber":25,"sourceCode":"    ModelLoadFailed,\n    ModelArchNotSupported,\n    ModelLoadTimedOut,\n    MissingSharedLibrary,\n    GpuDriverTooOld,\n\n    // --- Memory Errors ---\n    OutOfMemory,\n\n    // --- Configuration Errors ---\n    InvalidArgument,\n\n    // --- Internal Application Errors ---\n    IoError,\n    InternalError,\n}\n\n#[derive(Debug, Clone, Serialize, thiserror::Error)]\n#[error(\"LlamacppError {{ code: {code:?}, message: \\\"{message}\\\" }}\")]\npub struct LlamacppError {\n    pub code: ErrorCode,\n    pub message: String,\n    #[serde(skip_serializing_if = \"Option::is_none\")]\n    pub details: Option<String>,\n    /// Library names the loader could not resolve, so the UI can turn them into\n    /// install advice instead of showing raw engine output.\n    #[serde(skip_serializing_if = \"Option::is_none\")]\n    pub missing_libraries: Option<Vec<String>>,\n}\n\nimpl LlamacppError {\n    pub fn new(code: ErrorCode, message: String, details: Option<String>) -> Self {\n        Self {\n            code,\n            message,\n            details,\n            missing_libraries: None,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/error.rs#L7-L43","documentation":"LlamacppError is the plugin's structured error type, carrying an ErrorCode discriminant, a human-readable message, optional details, and loader library names. It is thrown by any command or routine inside tauri-plugin-llamacpp that fails, and its Display renders code and message so the frontend can branch on code. It exists so all plugin failures funnel into one serializable shape for Tauri IPC.","triggerScenarios":"Any plugin operation that wraps a failure into LlamacppError::new(code, message): server start/stop failures, model download or load errors, process management failures, or loader resolution failures (which populate the library_names field).","commonSituations":"Missing or unloadable GGUF model files, llama.cpp shared libraries not found at runtime, server binary failing to spawn, or invalid model configuration passed from the UI.","solutions":["Read the error's code field and match it against the ErrorCode enum to identify the failing subsystem.","Inspect message and details for the underlying cause; check library_names if loader errors are reported.","Fix the underlying condition (model path, library availability, config) rather than catching generically.","Forward the structured error to the UI so it can render a code-specific message."],"exampleFix":"// before: treating every failure the same\nif let Err(e) = start_server(app, model) { eprintln!(\"failed: {}\", e); }\n// after: branch on the structured code\nmatch start_server(app, model) {\n    Err(e) if e.code == ErrorCode::IoError => eprintln!(\"io: {}\", e.message),\n    Err(e) => eprintln!(\"llamacpp {:?}: {}\", e.code, e.message),\n    Ok(_) => {}\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) => handle_llamacpp_error(&e.code, &e.message, e.details.as_deref(), e.library_names.as_deref()),\n    Ok(v) => proceed(v),\n}","preventionTips":["Always match on ErrorCode instead of string-matching messages.","Surface library_names to the UI so missing shared libraries are actionable.","Keep the error type serializable end-to-end so the frontend gets structure, not strings."],"tags":["rust","tauri","llamacpp","structured-error"],"backgroundTag":"api-error-response","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}