Flow-Launcher/Flow.Launcher · error · ArgumentException
Invalid file path
Error message
Invalid file path
What it means
Thrown as ArgumentException from the JsonStorage constructor when Path.GetDirectoryName(filePath) returns null. That happens when filePath is a root (e.g. 'C:\'), a UNC root, or an invalid path string with no directory component. The constructor then immediately calls FilesFolders.ValidateDirectory(DirectoryPath), so this guard ensures DirectoryPath is never null before validation.
Solutions
- Inspect the filePath passed to the JsonStorage constructor — it should be a full path like 'C:\Users\...\plugin\settings.json'.
- Ensure the base directory (BaseDirectory / DataDirectory) is non-empty before combining with the filename.
- Use Path.Combine with an explicit, validated directory rather than building the path manually.
- Log the filePath at construction time in your subclass to catch bad inputs during development.
Example fix
// before
public JsonStorage(string filePath)
{
FilePath = filePath;
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
}
// after — validate and report the offending path
DirectoryPath = Path.GetDirectoryName(filePath);
if (string.IsNullOrEmpty(DirectoryPath))
throw new ArgumentException($"Invalid file path (no directory component): '{filePath}'", nameof(filePath)); Defensive patterns
Strategy: validation
Validate before calling
var dir = Path.GetDirectoryName(filePath);
if (string.IsNullOrEmpty(dir))
throw new ArgumentException($"Storage path has no directory: '{filePath}'", nameof(filePath));
FilesFolders.ValidateDirectory(dir); Type guard
static bool IsValidStoragePath(string p) =>
!string.IsNullOrWhiteSpace(p) && !string.IsNullOrEmpty(Path.GetDirectoryName(p))
&& Path.GetInvalidPathChars().All(c => !p.Contains(c)); Try / catch
null
Prevention
- Always build storage paths with Path.Combine(validatedBaseDirectory, fileName).
- Assert the base directory is non-empty before constructing the path.
- Log the filePath at construction in subclasses to catch bad inputs early.
- Unit-test storage construction with edge-case paths.
When it happens
Trigger: A storage subclass or caller constructs JsonStorage with a path that has no directory portion: a bare filename resolved against the current drive root, a path like '\', 'C:', or an empty/malformed string that Path.GetDirectoryName treats as rootless. Most commonly a misconfigured BaseDirectory or a plugin passing a relative path that resolved unexpectedly.
Common situations: A plugin's settings path computed from a config value that is empty or root-only; a path constructed by combining an empty base directory with a filename that itself contains no directory; passing an already-rooted drive letter without a subfolder; misconfigured portable-mode DataDirectory.
Related errors
- DoublePinyinSchema ' ' is invalid or double pinyin table is…
- Failed to deserialize double pinyin table: result is null
- Theme path can't be found <
- Failed to parse file path
- Failed to parse folder path
AI-assisted analysis of Flow-Launcher/Flow.Launcher@7fc63b07bb (2026-08-13).
Data as JSON: /api/errors/6f4e51339135831b.
Report an issue: GitHub.
Appendix: source
Thrown at Flow.Launcher.Infrastructure/Storage/JsonStorage.cs:43
public const string FileSuffix = ".json";
protected string FilePath { get; init; } = null!;
private string TempFilePath => $"{FilePath}.tmp";
private string BackupFilePath => $"{FilePath}.bak";
protected string DirectoryPath { get; init; } = null!;
// Let the derived class to set the file path
protected JsonStorage()
{
}
public JsonStorage(string filePath)
{
FilePath = filePath;
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
FilesFolders.ValidateDirectory(DirectoryPath);
}
public bool Exists()
{
return File.Exists(FilePath);
}
public void Delete()
{
foreach (var path in new[] { FilePath, BackupFilePath, TempFilePath })
{
if (File.Exists(path))
{
File.Delete(path);
}
}View on GitHub (pinned to 7fc63b07bb)