{"record":{"id":"71981af326188937","repo":"JosefNemec/Playnite","slug":"database-path-cannot-be-empty","errorCode":null,"errorMessage":"Database path cannot be empty.","messagePattern":"Database path cannot be empty\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"source/Playnite/Database/GameDatabase.cs","lineNumber":506,"sourceCode":"            else if (path.Contains(\"%AppData%\", StringComparison.OrdinalIgnoreCase))\r\n            {\r\n                return path?.Replace(\"%AppData%\", Environment.ExpandEnvironmentVariables(\"%AppData%\"), StringComparison.OrdinalIgnoreCase);\r\n            }\r\n            else if (!Paths.IsFullPath(path))\r\n            {\r\n                return Path.GetFullPath(path);\r\n            }\r\n            else\r\n            {\r\n                return path;\r\n            }\r\n        }\r\n\r\n        public void OpenDatabase()\r\n        {\r\n            if (string.IsNullOrEmpty(DatabasePath))\r\n            {\r\n                throw new Exception(\"Database path cannot be empty.\");\r\n            }\r\n\r\n            var dbExists = File.Exists(DatabaseFileSettingsPath);\r\n            logger.Info(\"Opening db \" + DatabasePath);\r\n\r\n            if (!FileSystem.CanWriteToFolder(DatabasePath))\r\n            {\r\n                throw new Exception($\"Can't write to \\\"{DatabasePath}\\\" folder.\");\r\n            }\r\n\r\n            // This fixes an issue where people mess up their library with custom scripts\r\n            // which create collection files instead of directories :|\r\n            if (File.Exists(FilesDirectoryPath))\r\n            {\r\n                File.Delete(FilesDirectoryPath);\r\n            }\r\n\r\n            if (!dbExists)\r","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/JosefNemec/Playnite/blob/5911f4e964e628aa7a69c2030ab35101afa63067/source/Playnite/Database/GameDatabase.cs#L488-L524","documentation":"Thrown as a generic Exception by GameDatabase.OpenDatabase() when DatabasePath is null or empty. DatabasePath is the filesystem directory where the game database resides; it must be set before OpenDatabase is called. This is a configuration/initialization contract violation.","triggerScenarios":"OpenDatabase is called before DatabasePath has been configured. The database path was cleared by a settings reset, a failed migration, or a corrupt settings file. A fresh Playnite install where the path initialization code did not run.","commonSituations":"First launch where path initialization failed or was skipped. Settings file corruption cleared the DatabasePath. A portable mode misconfiguration. A plugin or script cleared the path. Moving the database directory manually without updating settings.","solutions":["Set DatabasePath to a valid directory before calling OpenDatabase: gameDatabase.DatabasePath = @\"C:\\Games\\Playnite\\database\".","In normal (installed) mode, ensure Playnite's settings file is intact and the database path is configured in %AppData%\\Playnite.","In portable mode, ensure the portable directory is writable and the startup logic correctly resolves the database path.","Reset Playnite settings to defaults if the settings file is corrupt, then reconfigure the database location."],"exampleFix":"// before — calling OpenDatabase without setting path\ngameDatabase.OpenDatabase(); // throws if DatabasePath is empty\n\n// after — ensure path is set\ngameDatabase.DatabasePath = PlaynitePaths.DatabaseDir;\nif (string.IsNullOrEmpty(gameDatabase.DatabasePath))\n    throw new InvalidOperationException(\"Database path not configured.\");\ngameDatabase.OpenDatabase();","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(gameDatabase.DatabasePath))\n{\n    gameDatabase.DatabasePath = PlaynitePaths.DatabaseDir;\n    if (string.IsNullOrEmpty(gameDatabase.DatabasePath))\n        throw new InvalidOperationException(\"Database path could not be resolved.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize DatabasePath during application startup before any database operations.","Add a startup health check that verifies DatabasePath is set and the directory exists.","Use PlaynitePaths constants to derive the default path consistently."],"tags":["database","configuration","initialization","validation","game-database"],"backgroundTag":null,"analyzedSha":"5911f4e964e628aa7a69c2030ab35101afa63067","analyzedAt":"2026-08-13T17:38:25.713Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}