SubtitleEdit/subtitleedit · error · CoreError

Could not parse response: {e.Message}

Error message

Could not parse response: {e.Message}

What it means

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.

Source

Thrown at src/ui/Logic/Ocr/GoogleLens/Core.cs:224

                }
                await Task.Delay(500);
                return await FetchAsync(formdata, originalDimensions, true);
            }
        }

        if (response.StatusCode != System.Net.HttpStatusCode.OK)
        {
            throw new CoreError("Lens returned a non-200 status code", (int)response.StatusCode, response.Headers, text);
        }

        try
        {
            var afData = GetAFData(responseBody);
            return ParseResult(afData!, originalDimensions);
        }
        catch (Exception e)
        {
            throw new CoreError($"Could not parse response: {e.Message}", (int)response.StatusCode, response.Headers, text);
        }
    }
    
    public async Task<List<string>> ScanByData(byte[] uint8, string mime, int[] originalDimensions)
    {
        if (!Constants.SUPPORTED_MIMES.Contains(mime))
        {
            throw new Exception("File type not supported");
        }
        if (originalDimensions == null)
        {
            throw new Exception("Original dimensions not set");
        }

        string fileName = $"image.{Constants.MIME_TO_EXT[mime]}";
        var dimensions = Helper.ImageDimensionsFromData(uint8);

        var width = dimensions.Width;

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Log CoreError's response text to see the actual Lens payload and locate the schema change.
  2. Update the AF_initDataCallback regex / DetectedObject detection to match the new format.
  3. Fall back to an alternative OCR engine when parsing fails.
  4. Retry once in case of a transient malformed response.

Example fix

// before
var result = await core.FetchAsync(formdata, dims);

// after
try { var result = await core.FetchAsync(formdata, dims); }
catch (CoreError ex) when (ex.Message.Contains("Could not parse")) { Log(ex.ResponseText); return await FallbackOcrAsync(image); }
Defensive patterns

Strategy: fallback

Validate before calling

// Cannot prevent schema drift, but log to detect it early.
// Optionally probe a known-good image first to detect format changes.

Try / catch

try { var r = await core.FetchAsync(formdata, dims); }
catch (CoreError ex) when (ex.Message.Contains("Could not parse"))
{ File.WriteAllText("lens-debug.txt", ex.ResponseText); return await FallbackOcrAsync(image); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/0e19a4dd090b6661. Report an issue: GitHub.