{"record":{"id":"13fe5c495f9a5048","repo":"ppy/osu","slug":"path-is-not-a-valid-archive","errorCode":null,"errorMessage":"{Path} is not a valid archive","messagePattern":"(.+?) is not a valid archive","errorType":"exception","errorClass":"InvalidFormatException","httpStatus":null,"severity":"error","filePath":"osu.Game/Database/ImportTask.cs","lineNumber":58,"sourceCode":"            Path = filename;\r\n            Stream = stream;\r\n        }\r\n\r\n        /// <summary>\r\n        /// Retrieve an archive reader from this task.\r\n        /// </summary>\r\n        public ArchiveReader GetReader()\r\n        {\r\n            if (Stream == null)\r\n            {\r\n                if (ZipUtils.IsZipArchive(Path))\r\n                    return new ZipArchiveReader(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read), System.IO.Path.GetFileName(Path));\r\n                if (Directory.Exists(Path))\r\n                    return new DirectoryArchiveReader(Path);\r\n                if (File.Exists(Path))\r\n                    return new SingleFileArchiveReader(Path);\r\n\r\n                throw new InvalidFormatException($\"{Path} is not a valid archive\");\r\n            }\r\n\r\n            if (Stream is not MemoryStream memoryStream)\r\n            {\r\n                // Path used primarily in tests (converting `ManifestResourceStream`s to `MemoryStream`s).\r\n                memoryStream = new MemoryStream(Stream.ReadAllBytesToArray());\r\n                Stream.Dispose();\r\n            }\r\n\r\n            if (ZipUtils.IsZipArchive(memoryStream))\r\n                return new ZipArchiveReader(memoryStream, Path);\r\n\r\n            return new MemoryStreamArchiveReader(memoryStream, Path);\r\n        }\r\n\r\n        /// <summary>\r\n        /// Deletes the file that is encapsulated by this <see cref=\"ImportTask\"/>.\r\n        /// </summary>\r","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Database/ImportTask.cs#L40-L76","documentation":"Thrown by ImportTask.GetReader when the path is not recognized as any supported archive type: it's not a zip file (ZipUtils.IsZipArchive returns false), not a directory (Directory.Exists returns false), and not a file (File.Exists returns false). This is the path-based branch where no Stream was provided to the ImportTask.","triggerScenarios":"Constructing `new ImportTask(path)` (path-based, no stream) and calling GetReader() where: the file doesn't exist at all, the path is a broken symlink, the file exists but isn't a valid zip (and somehow passes the File.Exists check but not IsZipArchive — actually the File.Exists branch returns SingleFileArchiveReader, so this throw fires when the path simply doesn't exist as file or directory and isn't a zip).","commonSituations":"Passing a path to an ImportTask where the file was deleted between task creation and GetReader call; a typo in the path; a path that points to a special file or broken symlink; a network path that's inaccessible.","solutions":["Verify the path exists before creating the ImportTask: check File.Exists(path) || Directory.Exists(path).","Ensure the path is absolute and correctly formatted.","If importing a zip, verify ZipUtils.IsZipArchive(path) returns true.","If the file was moved or deleted, provide the correct current path or use the stream-based ImportTask constructor."],"exampleFix":"// before\nvar task = new ImportTask(path);\nvar reader = task.GetReader(); // throws if path doesn't exist\n\n// after\nif (!File.Exists(path) && !Directory.Exists(path))\n    throw new FileNotFoundException($\"Archive not found: {path}\", path);\nvar task = new ImportTask(path);\nvar reader = task.GetReader();","handlingStrategy":"validation","validationCode":"// Validate path before creating ImportTask\nif (!File.Exists(path) && !Directory.Exists(path))\n    throw new FileNotFoundException($\"Path is not a valid archive: {path}\", path);\nvar task = new ImportTask(path);","typeGuard":"static bool IsValidArchivePath(string path)\n    => File.Exists(path) || Directory.Exists(path);","tryCatchPattern":"try\n{\n    var reader = task.GetReader();\n}\ncatch (InvalidFormatException ex) when (ex.Message.Contains(\"not a valid archive\"))\n{\n    Logger.Log($\"Invalid archive path: {task.Path}\", LoggingTarget.Database);\n}","preventionTips":["Verify the path exists (File.Exists or Directory.Exists) before constructing a path-based ImportTask.","Use the stream-based ImportTask constructor for in-memory data.","Handle file-not-found gracefully at the UI layer and prompt for a valid file."],"tags":["archive","import","io","file-not-found","validation"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}