{"record":{"id":"9b003f0db7d1c71a","repo":"Kareadita/Kavita","slug":"invalid-metadata-provider","errorCode":"invalid-metadata-provider","errorMessage":"invalid-metadata-provider","messagePattern":"invalid-metadata-provider","errorType":"exception","errorClass":"KavitaException","httpStatus":400,"severity":"warning","filePath":"Kavita.Server/Controllers/LibraryController.cs","lineNumber":774,"sourceCode":"\n        library.LibraryFileTypes = dto.FileGroupTypes\n            .Select(t => new LibraryFileTypeGroup() {FileTypeGroup = t, LibraryId = library.Id})\n            .Distinct()\n            .ToList();\n\n        library.LibraryExcludePatterns = dto.ExcludePatterns\n            .Distinct()\n            .Select(t => new LibraryExcludePattern() {Pattern = t, LibraryId = library.Id})\n            .ToList();\n\n        unitOfWork.LibraryRepository.Update(library);\n    }\n\n    private static void ValidateMetadataProvider(LibraryType type, MetadataProvider provider)\n    {\n        if (!KavitaPlusConfiguration.MetadataProvidersForLibraryTypes.TryGetValue(type, out var validProviders) || !validProviders.Contains(provider))\n        {\n            throw new KavitaException(\"invalid-metadata-provider\");\n        }\n    }\n\n    /// <summary>\n    /// Returns the type of the underlying library\n    /// </summary>\n    /// <param name=\"libraryId\"></param>\n    /// <returns></returns>\n    [LibraryAccess]\n    [HttpGet(\"type\")]\n    public async Task<ActionResult<LibraryType>> GetLibraryType(int libraryId)\n    {\n        var ct = HttpContext.RequestAborted;\n        return Ok(await unitOfWork.LibraryRepository.GetLibraryTypeAsync(libraryId, ct));\n    }\n}\n","sourceCodeStart":756,"sourceCodeEnd":791,"githubUrl":"https://github.com/Kareadita/Kavita/blob/9c3e5400007f8a0282f7d883f2ad5e71716e514d/Kavita.Server/Controllers/LibraryController.cs#L756-L791","documentation":"Thrown by LibraryController.ValidateMetadataProvider when the supplied MetadataProvider is not valid for the given LibraryType, per KavitaPlusConfiguration.MetadataProvidersForLibraryTypes (e.g. only Mangabaka for Manga, Hardcover/ComicBookRoundup for Comic). A KavitaException surfacing as HTTP 500 with 'invalid-metadata-provider'.","triggerScenarios":"A library update/create call sets a MetadataProvider not in the allowed set for that LibraryType — e.g. choosing Hardcover for a Manga library, or ComicBookRoundup for LightNovel when unsupported.","commonSituations":"UI offers a provider combo invalid for the library type; the MetadataProvidersForLibraryTypes map changed across versions but the client wasn't updated; misconfigured Kavita Plus provider selection.","solutions":["Choose a MetadataProvider that the library's LibraryType allows per MetadataProvidersForLibraryTypes.","Fetch valid providers via the endpoint that returns MetadataProvidersForLibraryTypes for the type, then restrict the UI selector.","Keep the client's provider list in sync with the server map (note the source comment to adjust UI when the map changes)."],"exampleFix":"// before - Hardcover not valid for Manga\nValidateMetadataProvider(LibraryType.Manga, MetadataProvider.Hardcover);\n\n// after - Mangabaka is the allowed provider for Manga\nValidateMetadataProvider(LibraryType.Manga, MetadataProvider.Mangabaka);","handlingStrategy":"validation","validationCode":"if (!KavitaPlusConfiguration.MetadataProvidersForLibraryTypes\n        .TryGetValue(type, out var valid) || !valid.Contains(provider))\n    return BadRequest(\"invalid-metadata-provider\");","typeGuard":"static bool IsValidProvider(LibraryType t, MetadataProvider p)\n    => KavitaPlusConfiguration.MetadataProvidersForLibraryTypes\n       .TryGetValue(t, out var set) && set.Contains(p);","tryCatchPattern":"try { ValidateMetadataProvider(type, provider); }\ncatch (KavitaException) { return BadRequest(\"invalid-metadata-provider\"); }","preventionTips":["Fetch valid providers for the type from the server before rendering the selector.","Recompute the allowed set client-side when the LibraryType changes.","Update the client map whenever the server MetadataProvidersForLibraryTypes changes."],"tags":["library","validation","kavita-plus","metadata","input"],"backgroundTag":null,"analyzedSha":"9c3e5400007f8a0282f7d883f2ad5e71716e514d","analyzedAt":"2026-08-13T19:06:05.897Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}