{"record":{"id":"bc01d879de584949","repo":"QL-Win/QuickLook","slug":"unsupported-file-type-ext","errorCode":null,"errorMessage":"Unsupported file type: {ext}","messagePattern":"Unsupported file type: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs","lineNumber":85,"sourceCode":"            {\n                if (!SettingHelper.Get(\"RenderSvgWeb\", true, \"QuickLook.Plugin.ImageViewer\"))\n                {\n                    metaWeb = null;\n                    return false;\n                }\n            }\n\n            metaWeb = ext switch\n            {\n                \".svg\" => new SvgMetaProvider(path),\n                \".svga\" => new SvgaMetaProvider(path),\n                \".lottie\" or \".json\" => new LottieMetaProvider(path),\n                \".tgs\" => new TgsMetaProvider(path),\n                \".gv\" or \".dot\" => new GvMetaProvider(),\n                \".pu\" or \".puml\" or \".plantuml\" or \".wsd\" or \".iuml\" => new PuMetaProvider(),\n                \".drawio\" or \".dio\" => new DrawioMetaProvider(),\n                \".excalidraw\" => new ExcalidrawMetaProvider(),\n                _ => throw new NotSupportedException($\"Unsupported file type: {ext}\")\n            };\n            var sizeSvg = metaWeb.GetSize();\n\n            if (!sizeSvg.IsEmpty)\n                context.SetPreferredSizeFit(sizeSvg, 0.8d);\n            else\n                context.PreferredSize = new Size(800, 600);\n\n            context.Theme = (Themes)SettingHelper.Get(\"LastTheme\", 1, \"QuickLook.Plugin.ImageViewer\");\n            return true;\n        }\n\n        metaWeb = null;\n        return false;\n    }\n\n    public static bool TryView(string path, ContextObject context, IWebMetaProvider metaWeb, out IWebImagePanel ipWeb)\n    {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs#L67-L103","documentation":"Thrown in WebHandler.TryPrepare as the default arm of the extension switch selecting an IWebMetaProvider. The supported extensions are svg, svga, lottie/json, tgs, gv/dot, pu/puml/plantuml/wsd/iuml, drawio/dio, excalidraw. In practice this arm is defensive: TryPrepare is only entered after an outer `if` that checks the same extension set, so the throw is effectively unreachable unless the two lists diverge or the method is called directly with an unguarded extension.","triggerScenarios":"Path.GetExtension(path).ToLower() returns a value not in the switch, AND the preceding guard `if` was bypassed (e.g. the lists are edited inconsistently, or TryPrepare is invoked directly without the guard).","commonSituations":"A new extension is added to the outer guard `if` but forgotten in the switch (or vice-versa); a caller invokes TryPrepare on a path it did not pre-screen with TryCanHandle.","solutions":["Always gate TryPrepare behind TryCanHandle(path) so only whitelisted extensions reach the switch.","Keep the extension lists in the guard `if` and the switch in sync (extract a shared HashSet<string> of supported extensions).","If hit during development, add the missing extension case or remove it from the guard.","Catch NotSupportedException and return false from the plugin rather than crashing the preview."],"exampleFix":"// before — duplicated lists drift apart\nif (ext == \".svg\" || ext == \".svga\" /* ... */)\n    metaWeb = ext switch { /* ... */ _ => throw new NotSupportedException(...) };\n\n// after — single source of truth\nstatic readonly HashSet<string> WebExts = new(){\".svg\",\".svga\",\".lottie\",\".json\",\".tgs\",\".gv\",\".dot\",\".pu\",\".puml\",\".plantuml\",\".wsd\",\".iuml\",\".drawio\",\".dio\",\".excalidraw\"};\nif (!WebExts.Contains(ext)) { metaWeb = null; return false; }","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> WebExts = new(){\".svg\",\".svga\",\".lottie\",\".json\",\".tgs\",\".gv\",\".dot\",\".pu\",\".puml\",\".plantuml\",\".wsd\",\".iuml\",\".drawio\",\".dio\",\".excalidraw\"};\nstring ext = Path.GetExtension(path).ToLower();\nif (!WebExts.Contains(ext)) return false;","typeGuard":"static bool IsWebExt(string ext) => WebExts.Contains(ext);","tryCatchPattern":"try { if (!WebHandler.TryPrepare(path, ctx, out var meta)) { /* not handled */ } }\ncatch (NotSupportedException) { /* extension lists drifted; log and skip */ }","preventionTips":["Gate TryPrepare behind TryCanHandle.","Keep a single shared extension set for guard and switch.","Add new extensions to both the guard and the switch atomically."],"tags":["webview","image","file-type","switch","quicklook"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}