ZhuLinsen/daily_stock_analysis · warning · Error

Desktop share image source did not return HTML

Error message

Desktop share image source did not return HTML

What it means

Raised by PortfolioService.query_corporate_actions when date_from and date_to are both provided and date_from is after date_to. Pre-query guard identical in shape to the trades and cash-ledger range checks.

Source

Thrown at apps/dsa-desktop/main.js:1422

        sandbox: true,
        backgroundThrottling: false,
      },
    });
    renderWindow.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
    renderWindow.webContents.on('will-navigate', (event, navigationUrl) => {
      if (navigationUrl !== targetUrl) {
        event.preventDefault();
      }
    });

    await renderWindow.loadURL(targetUrl);
    const pageMetrics = await renderWindow.webContents.executeJavaScript(`({
      contentType: document.contentType,
      width: Math.ceil(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth)),
      height: Math.ceil(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight))
    })`);
    if (!pageMetrics || pageMetrics.contentType !== 'text/html') {
      throw new Error('Desktop share image source did not return HTML');
    }
    if (
      !Number.isFinite(pageMetrics.width)
      || pageMetrics.width !== DESKTOP_SHARE_IMAGE_WIDTH
      || !Number.isFinite(pageMetrics.height)
      || pageMetrics.height < 1
      || pageMetrics.height > DESKTOP_SHARE_IMAGE_MAX_HEIGHT
    ) {
      throw new Error(`Desktop share image has invalid dimensions: ${pageMetrics.width}x${pageMetrics.height}`);
    }

    renderWindow.setContentSize(DESKTOP_SHARE_IMAGE_WIDTH, pageMetrics.height);
    await renderWindow.webContents.executeJavaScript(
      'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
    );
    const image = await renderWindow.webContents.capturePage({
      x: 0,
      y: 0,

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Normalize the pair (min, max) before calling the service
  2. Correct the argument order at the call site (keyword args make the bug obvious: date_from must be earlier)
  3. Validate the range in the frontend and block submission of inverted ranges
  4. Add a unit test covering the inverted-range path for each query endpoint you build

Example fix

# before
svc.query_corporate_actions(date_from=q_end, date_to=q_start)
# after
svc.query_corporate_actions(date_from=min(q_start, q_end), date_to=max(q_start, q_end))
Defensive patterns

Strategy: validation

Validate before calling

def safe_range(date_from, date_to):
    if date_from and date_to and date_from > date_to:
        date_from, date_to = date_to, date_from
    return date_from, date_to

Type guard

from datetime import date

def is_valid_date_range(d_from: date | None, d_to: date | None) -> bool:
    return d_from is None or d_to is None or d_from <= d_to

Try / catch

try:
    svc.query_corporate_actions(date_from=f, date_to=t)
except ValueError as exc:
    if "date_from must be <= date_to" in str(exc):
        f, t = t, f
        svc.query_corporate_actions(date_from=f, date_to=t)
    else:
        raise

Prevention

When it happens

Trigger: GET /portfolio/corporate-actions?date_from=2025-06-30&date_to=2025-01-01 or the direct call with inverted date arguments. Equal dates are accepted.

Common situations: Dividend-history widgets whose default range is built from unix timestamps converted to dates inconsistently; queries generated from user-typed free-text dates parsed in the wrong order; shared date-range helper passing (to, from) positional args.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/257726eaec23157b. Report an issue: GitHub.