{"record":{"id":"0e19a4dd090b6661","repo":"SubtitleEdit/subtitleedit","slug":"could-not-parse-response-e-message","errorCode":null,"errorMessage":"Could not parse response: {e.Message}","messagePattern":"Could not parse response: (.+?)","errorType":"exception","errorClass":"CoreError","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Ocr/GoogleLens/Core.cs","lineNumber":224,"sourceCode":"                }\n                await Task.Delay(500);\n                return await FetchAsync(formdata, originalDimensions, true);\n            }\n        }\n\n        if (response.StatusCode != System.Net.HttpStatusCode.OK)\n        {\n            throw new CoreError(\"Lens returned a non-200 status code\", (int)response.StatusCode, response.Headers, text);\n        }\n\n        try\n        {\n            var afData = GetAFData(responseBody);\n            return ParseResult(afData!, originalDimensions);\n        }\n        catch (Exception e)\n        {\n            throw new CoreError($\"Could not parse response: {e.Message}\", (int)response.StatusCode, response.Headers, text);\n        }\n    }\n    \n    public async Task<List<string>> ScanByData(byte[] uint8, string mime, int[] originalDimensions)\n    {\n        if (!Constants.SUPPORTED_MIMES.Contains(mime))\n        {\n            throw new Exception(\"File type not supported\");\n        }\n        if (originalDimensions == null)\n        {\n            throw new Exception(\"Original dimensions not set\");\n        }\n\n        string fileName = $\"image.{Constants.MIME_TO_EXT[mime]}\";\n        var dimensions = Helper.ImageDimensionsFromData(uint8);\n\n        var width = dimensions.Width;","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Ocr/GoogleLens/Core.cs#L206-L242","documentation":"Thrown by Core.FetchAsync when GetAFData or ParseResult throws while processing an otherwise-200 Lens response. The inner exception's message is concatenated into a CoreError along with status, headers, and text. It signals that Lens returned data but the expected AF_initDataCallback / DetectedObject structure was missing or shaped differently than the parser expects — typically a Google-side response-format change.","triggerScenarios":"Lens returns 200 with HTML/JS that does not contain the DetectedObject callback, or where JObject.Parse fails because the extracted JSON is malformed, or ParseResult's index-based navigation hits a null/missing node.","commonSituations":"Google pushed a new Lens response schema; the response is a captcha/consent page served with 200; a regional variant returns a different structure; a transient partial response.","solutions":["Log CoreError's response text to see the actual Lens payload and locate the schema change.","Update the AF_initDataCallback regex / DetectedObject detection to match the new format.","Fall back to an alternative OCR engine when parsing fails.","Retry once in case of a transient malformed response."],"exampleFix":"// before\nvar result = await core.FetchAsync(formdata, dims);\n\n// after\ntry { var result = await core.FetchAsync(formdata, dims); }\ncatch (CoreError ex) when (ex.Message.Contains(\"Could not parse\")) { Log(ex.ResponseText); return await FallbackOcrAsync(image); }","handlingStrategy":"fallback","validationCode":"// Cannot prevent schema drift, but log to detect it early.\n// Optionally probe a known-good image first to detect format changes.","typeGuard":null,"tryCatchPattern":"try { var r = await core.FetchAsync(formdata, dims); }\ncatch (CoreError ex) when (ex.Message.Contains(\"Could not parse\"))\n{ File.WriteAllText(\"lens-debug.txt\", ex.ResponseText); return await FallbackOcrAsync(image); }","preventionTips":["Log CoreError.ResponseText whenever parsing fails to detect schema changes.","Update the AF_initDataCallback regex/DetectedObject marker when Google changes it.","Provide a fallback OCR engine.","Retry once for transient malformed responses."],"tags":["google-lens","ocr","parsing","network","schema","fragile"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}