{"record":{"id":"6560e18fe6ce01ef","repo":"jackwener/OpenCLI","slug":"linkedin-learning-courses-lookup-returned-malforme","errorCode":null,"errorMessage":"LinkedIn Learning courses lookup returned malformed payload: missing elements array","messagePattern":"LinkedIn Learning courses lookup returned malformed payload: missing elements array","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin-learning/course.js","lineNumber":81,"sourceCode":"    domain: DOMAIN,\n    strategy: Strategy.COOKIE,\n    browser: true,\n    args: [\n        { name: 'slug', type: 'string', required: true, positional: true, help: 'Course slug (e.g. agentic-ai-build-your-first-agentic-ai-system) or full /learning/<slug> URL' },\n    ],\n    columns: ['title', 'slug', 'description', 'difficulty', 'duration_sec', 'videos_count', 'rating', 'rating_count', 'released', 'url'],\n    func: async (page, args) => {\n        if (!page) throw new CommandExecutionError('Browser session required for linkedin-learning course');\n        const slug = parseSlug(args.slug);\n\n        const url = `https://www.linkedin.com/learning-api/courses?q=slug&slug=${encodeURIComponent(slug)}`;\n        const result = await fetchLinkedInLearningApi(page, url);\n        if (!result?.json) {\n            throw new CommandExecutionError(`LinkedIn Learning courses lookup failed: ${result?.error ?? 'no payload'}`);\n        }\n        const elements = result.json?.elements;\n        if (!Array.isArray(elements)) {\n            throw new CommandExecutionError('LinkedIn Learning courses lookup returned malformed payload: missing elements array');\n        }\n        const el = elements[0];\n        if (!el) {\n            throw new EmptyResultError(`No LinkedIn Learning course found for slug \"${slug}\"`);\n        }\n        const row = parseCourse(el, slug);\n        if (!row) {\n            throw new CommandExecutionError('LinkedIn Learning courses lookup returned malformed course detail: missing title');\n        }\n        return [row];\n    },\n});\n\nexport const __test__ = { parseSlug, parseCourse };\n","sourceCodeStart":63,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin-learning/course.js#L63-L96","documentation":"The learning-api returned JSON, but result.json.elements is not an array. The /learning-api/courses endpoint is expected to return { elements: [...] }; anything else (an error object, a JSON auth response, a changed schema) is treated as a malformed payload and rejected with this CommandExecutionError.","triggerScenarios":"The endpoint responds with valid JSON that lacks an elements array — e.g. an error/status JSON body, a login-related JSON response, or a LinkedIn API schema change where results moved to a different key.","commonSituations":"Session expired but server returned a JSON error envelope; LinkedIn rolled out an API version change; an intermediate proxy replaced the body with its own JSON error.","solutions":["Re-authenticate the browser session (expired cookies often produce non-course JSON) and retry.","Log the raw result.json to inspect the actual payload shape and confirm the API response schema.","Check for LinkedIn learning-api schema/auth changes; update the library if the elements key moved.","Retry later if it's a transient API-side issue; use search to cross-check that the service works."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const res = await fetchLinkedInLearningApi(page, apiUrl);\nif (res?.json && !Array.isArray(res.json?.elements)) {\n  console.warn('Unexpected learning-api payload:', res.json);\n}","typeGuard":"function hasElements(json) {\n  return json != null && typeof json === 'object' && Array.isArray(json.elements);\n}","tryCatchPattern":"try {\n  await runCommand('linkedin-learning', 'course', [slug]);\n} catch (e) {\n  if (e.message.includes('missing elements array')) {\n    await refreshSession(); // or inspect raw payload for schema change\n  } else throw e;\n}","preventionTips":["Log the raw response body whenever the shape check fails to spot schema drift early.","Re-authenticate when the payload looks like a JSON error/login envelope.","Pin and monitor library/CLI versions against LinkedIn learning-api changes."],"tags":["api-response","schema-change","linkedin-learning"],"backgroundTag":"unexpected-api-schema","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}