LykosAI/StabilityMatrix · error · DirectoryNotFoundException
Directory not found
Error message
Directory not found: {FullPath} What it means
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.
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
Example fix
// before
sourceDir.CopyTo(destDir);
// after
if (!sourceDir.Exists) { Logger.Warn("Source dir missing: {Path}", sourceDir.FullPath); return; }
sourceDir.CopyTo(destDir); Defensive patterns
Strategy: validation
Validate before calling
if (!sourceDir.Exists)
throw new DirectoryNotFoundException($"Source missing: {sourceDir.FullPath}"); Type guard
static bool IsExistingDir(DirectoryPath? d) => d is not null && d.Exists;
Try / catch
try { sourceDir.CopyTo(destDir); }
catch (DirectoryNotFoundException ex) { Logger.Warn("Copy skipped: {Msg}", ex.Message); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Copying preset/workspace folders whose location moved; migrating data directories before first launch when the folder is not yet initialized.
Related errors
- Source directory not found
- Source file does not exist
- Could not move file to
- Service type is not assignable to
- Service of type is not registered for
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/ee26e38c8b75d3cb.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Models/FileInterfaces/DirectoryPath.cs:145
/// Deletes the directory.
/// </summary>
/// <param name="recursive">Whether to delete subdirectories and files.</param>
public void Delete(bool recursive) => Info.Delete(recursive);
/// <summary>
/// Deletes the directory asynchronously.
/// </summary>
public Task DeleteAsync(bool recursive) => Task.Run(() => Delete(recursive));
void IPathObject.Delete() => Info.Delete(true);
Task IPathObject.DeleteAsync() => DeleteAsync(true);
private void ThrowIfNotExists()
{
if (!Exists)
{
throw new DirectoryNotFoundException($"Directory not found: {FullPath}");
}
}
public void CopyTo(DirectoryPath destinationDir, bool recursive = true)
{
ThrowIfNotExists();
// Cache directories before we start copying
var dirs = EnumerateDirectories().ToList();
destinationDir.Create();
// Get the files in the source directory and copy to the destination directory
foreach (var file in EnumerateFiles())
{
var targetFilePath = destinationDir.JoinFile(file.Name);
file.CopyTo(targetFilePath);
}View on GitHub (pinned to af93d6ef57)