{"record":{"id":"257726eaec23157b","repo":"ZhuLinsen/daily_stock_analysis","slug":"desktop-share-image-source-did-not-return-html","errorCode":null,"errorMessage":"Desktop share image source did not return HTML","messagePattern":"Desktop share image source did not return HTML","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"apps/dsa-desktop/main.js","lineNumber":1422,"sourceCode":"        sandbox: true,\n        backgroundThrottling: false,\n      },\n    });\n    renderWindow.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));\n    renderWindow.webContents.on('will-navigate', (event, navigationUrl) => {\n      if (navigationUrl !== targetUrl) {\n        event.preventDefault();\n      }\n    });\n\n    await renderWindow.loadURL(targetUrl);\n    const pageMetrics = await renderWindow.webContents.executeJavaScript(`({\n      contentType: document.contentType,\n      width: Math.ceil(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth)),\n      height: Math.ceil(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight))\n    })`);\n    if (!pageMetrics || pageMetrics.contentType !== 'text/html') {\n      throw new Error('Desktop share image source did not return HTML');\n    }\n    if (\n      !Number.isFinite(pageMetrics.width)\n      || pageMetrics.width !== DESKTOP_SHARE_IMAGE_WIDTH\n      || !Number.isFinite(pageMetrics.height)\n      || pageMetrics.height < 1\n      || pageMetrics.height > DESKTOP_SHARE_IMAGE_MAX_HEIGHT\n    ) {\n      throw new Error(`Desktop share image has invalid dimensions: ${pageMetrics.width}x${pageMetrics.height}`);\n    }\n\n    renderWindow.setContentSize(DESKTOP_SHARE_IMAGE_WIDTH, pageMetrics.height);\n    await renderWindow.webContents.executeJavaScript(\n      'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'\n    );\n    const image = await renderWindow.webContents.capturePage({\n      x: 0,\n      y: 0,","sourceCodeStart":1404,"sourceCodeEnd":1440,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/apps/dsa-desktop/main.js#L1404-L1440","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Normalize the pair (min, max) before calling the service","Correct the argument order at the call site (keyword args make the bug obvious: date_from must be earlier)","Validate the range in the frontend and block submission of inverted ranges","Add a unit test covering the inverted-range path for each query endpoint you build"],"exampleFix":"# before\nsvc.query_corporate_actions(date_from=q_end, date_to=q_start)\n# after\nsvc.query_corporate_actions(date_from=min(q_start, q_end), date_to=max(q_start, q_end))","handlingStrategy":"validation","validationCode":"def safe_range(date_from, date_to):\n    if date_from and date_to and date_from > date_to:\n        date_from, date_to = date_to, date_from\n    return date_from, date_to","typeGuard":"from datetime import date\n\ndef is_valid_date_range(d_from: date | None, d_to: date | None) -> bool:\n    return d_from is None or d_to is None or d_from <= d_to","tryCatchPattern":"try:\n    svc.query_corporate_actions(date_from=f, date_to=t)\nexcept ValueError as exc:\n    if \"date_from must be <= date_to\" in str(exc):\n        f, t = t, f\n        svc.query_corporate_actions(date_from=f, date_to=t)\n    else:\n        raise","preventionTips":["Normalize ranges once in a shared client helper","Validate parsed free-text dates for order before querying","Prefer keyword arguments so from/to mix-ups are visible"],"tags":["portfolio","validation","date-range","corporate-action"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}