{"record":{"id":"ee26e38c8b75d3cb","repo":"LykosAI/StabilityMatrix","slug":"directory-not-found-fullpath","errorCode":null,"errorMessage":"Directory not found: {FullPath}","messagePattern":"Directory not found: (.+?)","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Models/FileInterfaces/DirectoryPath.cs","lineNumber":145,"sourceCode":"    /// Deletes the directory.\n    /// </summary>\n    /// <param name=\"recursive\">Whether to delete subdirectories and files.</param>\n    public void Delete(bool recursive) => Info.Delete(recursive);\n\n    /// <summary>\n    /// Deletes the directory asynchronously.\n    /// </summary>\n    public Task DeleteAsync(bool recursive) => Task.Run(() => Delete(recursive));\n\n    void IPathObject.Delete() => Info.Delete(true);\n\n    Task IPathObject.DeleteAsync() => DeleteAsync(true);\n\n    private void ThrowIfNotExists()\n    {\n        if (!Exists)\n        {\n            throw new DirectoryNotFoundException($\"Directory not found: {FullPath}\");\n        }\n    }\n\n    public void CopyTo(DirectoryPath destinationDir, bool recursive = true)\n    {\n        ThrowIfNotExists();\n\n        // Cache directories before we start copying\n        var dirs = EnumerateDirectories().ToList();\n\n        destinationDir.Create();\n\n        // Get the files in the source directory and copy to the destination directory\n        foreach (var file in EnumerateFiles())\n        {\n            var targetFilePath = destinationDir.JoinFile(file.Name);\n            file.CopyTo(targetFilePath);\n        }","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Models/FileInterfaces/DirectoryPath.cs#L127-L163","documentation":"DirectoryPath.ThrowIfNotExists is an internal guard used by DirectoryPath copy/delete operations. When the directory on disk does not exist it throws DirectoryNotFoundException with the full path. CopyTo/CopyToAsync require an existing source directory to enumerate its contents.","triggerScenarios":"Calling DirectoryPath.CopyTo(destinationDir) or CopyToAsync when the source DirectoryPath does not exist — path never created, wrong casing/drive, or deleted between listing and copy.","commonSituations":"Copying preset/workspace folders whose location moved; migrating data directories before first launch when the folder is not yet initialized.","solutions":["Check directoryPath.Exists before calling CopyTo/CopyToAsync","Create the source directory (or correct the stored path) if it should exist","Catch DirectoryNotFoundException and prompt the user to locate the folder","Re-run the operation after the folder is restored"],"exampleFix":"// before\nsourceDir.CopyTo(destDir);\n// after\nif (!sourceDir.Exists) { Logger.Warn(\"Source dir missing: {Path}\", sourceDir.FullPath); return; }\nsourceDir.CopyTo(destDir);","handlingStrategy":"validation","validationCode":"if (!sourceDir.Exists)\n    throw new DirectoryNotFoundException($\"Source missing: {sourceDir.FullPath}\");","typeGuard":"static bool IsExistingDir(DirectoryPath? d) => d is not null && d.Exists;","tryCatchPattern":"try { sourceDir.CopyTo(destDir); }\ncatch (DirectoryNotFoundException ex) { Logger.Warn(\"Copy skipped: {Msg}\", ex.Message); }","preventionTips":["Check DirectoryPath.Exists before any copy/delete operation","Initialize data directories on first launch before copying into them","Persist canonical absolute paths, not relative ones","Handle folder moves between sessions by re-resolving paths"],"tags":["csharp","file-io","directory"],"backgroundTag":"directory-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"}