{"record":{"id":"0337d0dbfde427dd","repo":"LykosAI/StabilityMatrix","slug":"model-file-no-longer-exists","errorCode":null,"errorMessage":"Model file no longer exists","messagePattern":"Model file no longer exists","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Services/ModelOrganizationService.cs","lineNumber":82,"sourceCode":"            Template = effectiveTemplate,\n            ScopePath = scopePath,\n            IncludeNested = includeNested,\n            Items = items,\n        };\n    }\n\n    /// <summary>\n    /// Moves a single model file into <paramref name=\"destinationDirectory\"/>, keeping its file\n    /// name and bringing the .cm-info.json / preview / .yaml sidecars along. Rolls back any\n    /// already-moved sidecars on failure. Throws <see cref=\"FileTransferExistsException\"/> when\n    /// a destination file already exists.\n    /// </summary>\n    public async Task MoveModelFileAsync(LocalModelFile model, string modelsRoot, string destinationDirectory)\n    {\n        var sourcePath = model.GetFullPath(modelsRoot);\n        if (!File.Exists(sourcePath))\n        {\n            throw new FileNotFoundException(\"Model file no longer exists\", sourcePath);\n        }\n\n        Directory.CreateDirectory(destinationDirectory);\n\n        var targetPath = Path.Combine(destinationDirectory, Path.GetFileName(sourcePath));\n        var moves = BuildFileMoves(sourcePath, targetPath);\n\n        await ApplyFileMovesAsync(moves).ConfigureAwait(false);\n    }\n\n    public async Task<ModelOrganizationApplyResult> ApplyPlan(ModelOrganizationPlan plan)\n    {\n        var movedCount = 0;\n        var skippedCount = plan.Items.Count(item => !item.CanApply);\n        var conflictCount = plan.ConflictCount;\n        var errors = new List<string>();\n\n        foreach (var item in plan.Items.Where(item => item.CanApply))","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Services/ModelOrganizationService.cs#L64-L100","documentation":"MoveModelFileAsync throws FileNotFoundException when the model's resolved source path (model.GetFullPath(modelsRoot)) does not exist on disk. The model file was indexed/registered but has since been deleted, moved, or was never present, so the move cannot proceed.","triggerScenarios":"Calling MoveModelFileAsync (directly or via ApplyPlan) with a LocalModelFile whose path under modelsRoot is missing — e.g. after the file was manually deleted, moved by another tool, or the modelsRoot is wrong.","commonSituations":"User deleted or renamed model files outside Stability Matrix; external symlinks broken after relocating a models folder; wrong modelsRoot passed (e.g. stable-diffusion vs lora root swapped); stale scan index after a folder change.","solutions":["Rescan/refresh the model library so stale entries pointing at deleted files are removed","Restore the missing file or correct modelsRoot so GetFullPath resolves to an existing path","Remove the stale model entry from the index before re-importing the file","Verify File.Exists on the resolved path before calling MoveModelFileAsync"],"exampleFix":"// before\nawait organizationService.MoveModelFileAsync(model, modelsRoot, destDir);\n// after\nvar path = model.GetFullPath(modelsRoot);\nif (!File.Exists(path))\n{\n    await libraryService.RescanAsync(); // drop stale entries\n    return;\n}\nawait organizationService.MoveModelFileAsync(model, modelsRoot, destDir);","handlingStrategy":"validation","validationCode":"var sourcePath = model.GetFullPath(modelsRoot);\nif (!File.Exists(sourcePath))\n{\n    await libraryService.RescanAsync();\n    return; // or re-import\n}","typeGuard":"bool ModelFileExists(LocalModelFile m, string root) => File.Exists(m.GetFullPath(root));","tryCatchPattern":"try\n{\n    await organizationService.MoveModelFileAsync(model, modelsRoot, destination);\n}\ncatch (FileNotFoundException ex)\n{\n    logger.LogWarning(ex, \"Model file missing: {Path}\", ex.FileName);\n    // rescan library to drop stale entries\n}","preventionTips":["Rescan the library after external file changes","Confirm correct modelsRoot for each model type","Verify file existence before moves"],"tags":["file","model-organization","file-not-found","move"],"backgroundTag":"file-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}