{"record":{"id":"b8772d3e7645921e","repo":"janhq/jan","slug":"mlxerror-code-code-message-message","errorCode":null,"errorMessage":"MlxError {{ code: {code:?}, message: \"{message}\" }}","messagePattern":"MlxError (.+?), message: \"(.+?)\" \\}\\}","errorType":"error_code","errorClass":"MlxError","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-mlx/src/error.rs","lineNumber":17,"sourceCode":"use serde::{Deserialize, Serialize};\n\n#[derive(Debug, Clone, Serialize, Deserialize)]\n#[serde(rename_all = \"SCREAMING_SNAKE_CASE\")]\npub enum ErrorCode {\n    BinaryNotFound,\n    ModelFileNotFound,\n    ModelLoadFailed,\n    ModelLoadTimedOut,\n    OutOfMemory,\n    MlxProcessError,\n    IoError,\n    InternalError,\n}\n\n#[derive(Debug, Clone, Serialize, thiserror::Error)]\n#[error(\"MlxError {{ code: {code:?}, message: \\\"{message}\\\" }}\")]\npub struct MlxError {\n    pub code: ErrorCode,\n    pub message: String,\n    #[serde(skip_serializing_if = \"Option::is_none\")]\n    pub details: Option<String>,\n}\n\nimpl MlxError {\n    pub fn new(code: ErrorCode, message: String, details: Option<String>) -> Self {\n        Self {\n            code,\n            message,\n            details,\n        }\n    }\n\n    /// Parses stderr from the MLX server and creates a specific MlxError.\n    pub fn from_stderr(stderr: &str) -> Self {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-mlx/src/error.rs#L1-L35","documentation":"MlxError is the structured error type of the tauri-plugin-mlx plugin: it pairs an ErrorCode enum (e.g. MlxProcessError, IoError, InternalError) with a human-readable message and optional details. It is thrown when MLX-side operations fail — spawning/communicating with the MLX process, filesystem IO, or internal plugin failures. Its Display renders code and message, and it serializes to the frontend including optional details.","triggerScenarios":"Any MLX plugin API call (model load, generate, server start) where the underlying MLX process errors, an IO operation fails, or the plugin hits an internal error; constructed with the corresponding ErrorCode variant.","commonSituations":"MLX binary missing or crashing; model path wrong or unreadable; insufficient memory on Apple Silicon; invalid generation parameters passed from the frontend.","solutions":["Read `code` and `message`/`details` on the error to identify the failing subsystem before changing code.","If code is MlxProcessError: check that the MLX runtime/binary exists and runs, and inspect its stderr output.","If code is IoError: verify model paths and file permissions.","If code is InternalError: update the plugin and report with the captured details string."],"exampleFix":"// before: string-matching the Display output\nif err.to_string().contains(\"process\") { restart(); }\n\n// after: match on the structured code\nmatch mlx_err.code {\n    ErrorCode::MlxProcessError => restart_mlx_process(),\n    ErrorCode::IoError => validate_model_path(),\n    ErrorCode::InternalError => log_and_report(mlx_err.details),\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"// Rust: narrow to the structured plugin error\nfn as_mlx_error(err: &ServerError) -> Option<&MlxError> {\n    match err { ServerError::Mlx(m) => Some(m), _ => None }\n}","tryCatchPattern":"match mlx_operation() {\n    Err(ServerError::Mlx(m)) => match m.code {\n        ErrorCode::MlxProcessError => restart_mlx(),\n        ErrorCode::IoError => check_paths(),\n        ErrorCode::InternalError => report_bug(&m.details),\n    },\n    Err(e) => forward(e),\n    Ok(v) => use(v),\n}","preventionTips":["Always match on ErrorCode, never on the Display string.","Propagate `details` into logs for support diagnostics.","Precheck model paths and MLX binary availability before invoking the plugin.","Pin plugin and MLX runtime versions together."],"tags":["mlx","rust","tauri","model-loading"],"backgroundTag":"internal-invariant-violation","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"}