{"record":{"id":"c90c9c9193ed1a1a","repo":"jackwener/OpenCLI","slug":"label-string-payload-error","errorCode":null,"errorMessage":"${label}: ${String(payload.error)}","messagePattern":"\\$\\{label\\}: \\$\\{String\\(payload\\.error\\)\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":207,"sourceCode":"// `Array.isArray(payload)` directly on the envelope silently see \"no data\" —\n// this matches the failure mode fixed for xiaohongshu/rednote (#1561) and\n// weibo (#1568).\n//\n// `unwrapEvaluateResult` is a defensive ternary: it unwraps when the payload\n// looks like an envelope, otherwise passes the value through unchanged so\n// older bridge versions and primitive return values still work.\n// ─────────────────────────────────────────────────────────────────────────────\nexport function unwrapEvaluateResult(payload) {\n    if (payload && !Array.isArray(payload) && typeof payload === 'object' && 'session' in payload && 'data' in payload) {\n        return payload.data;\n    }\n    return payload;\n}\n\nexport function requireArrayEvaluateResult(payload, label) {\n    if (!Array.isArray(payload)) {\n        if (payload && typeof payload === 'object' && 'error' in payload) {\n            throw new CommandExecutionError(`${label}: ${String(payload.error)}`);\n        }\n        throw new CommandExecutionError(`${label} returned malformed extraction payload`);\n    }\n    return payload;\n}\n\nexport function requireObjectEvaluateResult(payload, label) {\n    if (!payload || Array.isArray(payload) || typeof payload !== 'object') {\n        throw new CommandExecutionError(`${label} returned malformed extraction payload`);\n    }\n    return payload;\n}\n\nexport function requireBooleanEvaluateResult(payload, label) {\n    if (typeof payload !== 'boolean') {\n        throw new CommandExecutionError(`${label} returned malformed extraction payload`);\n    }\n    return payload;","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L189-L225","documentation":"requireArrayEvaluateResult validates that a page.evaluate extraction returned an array. If the injected script returned an object carrying an 'error' key (the in-page error envelope), the error string is rethrown as CommandExecutionError prefixed with the extraction label. Anything else non-array gets the generic malformed-payload message.","triggerScenarios":"A chatgpt extraction script running in page.evaluate hits an in-page exception and returns {error: '...'}, or the page DOM changed so the script returns a non-array object/null.","commonSituations":"ChatGPT UI update renaming selectors, page not fully loaded so the target list is undefined, or being on a page where the extraction script bails with its own error envelope.","solutions":["Read the ${label}: <error> text — it is the in-page script's own error message; fix the underlying condition (e.g. wait for the page to load)","Retry the command after the page finishes rendering","Verify you are on a chatgpt.com conversation/page the extractor supports","Update the opencli package if ChatGPT's DOM changed (selector drift)"],"exampleFix":"// before\nconst items = await getChatGPTVisibleImageUrls(page); // throws 'image urls: selector not found'\n// after\nawait page.waitForSelector('[data-testid=\"conversation\"]', { timeout: 15000 });\nconst items = await getChatGPTVisibleImageUrls(page);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isArrayEvaluatePayload(p) { return Array.isArray(p); }","tryCatchPattern":"try { items = await getChatGPTVisibleImageUrls(page); } catch (e) { if (e instanceof CommandExecutionError) { console.error('extraction failed:', e.message); /* retry after wait */ } else throw e; }","preventionTips":["Wait for the conversation DOM to render before extracting","Only run extractions on chatgpt.com pages","Read the '<label>: <error>' prefix — it carries the in-page cause","Keep opencli updated for ChatGPT DOM changes"],"tags":["browser-automation","page-evaluate","extraction"],"backgroundTag":"malformed-extraction-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}