{"record":{"id":"e2d99a49cbcf0ef2","repo":"jackwener/OpenCLI","slug":"unexpected-linkedin-learning-probe-json-stringi","errorCode":null,"errorMessage":"Unexpected LinkedIn Learning probe: ${JSON.stringify(result)}","messagePattern":"Unexpected LinkedIn Learning probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin-learning/auth.js","lineNumber":45,"sourceCode":"      if (!mini || !mini.publicIdentifier) {\n        return { kind: 'auth', detail: 'LinkedIn /voyager/api/me 200 but miniProfile missing' };\n      }\n      const firstName = (mini.firstName && (mini.firstName.text || mini.firstName)) || '';\n      const lastName = (mini.lastName && (mini.lastName.text || mini.lastName)) || '';\n      return {\n        ok: true,\n        public_id: String(mini.publicIdentifier),\n        plain_id: String(d.plainId || ''),\n        name: String((firstName + ' ' + lastName).trim()),\n      };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('linkedin.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /voyager/api/me`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`LinkedIn Learning whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected LinkedIn Learning probe: ${JSON.stringify(result)}`);\n  return { public_id: result.public_id, plain_id: result.plain_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'linkedin-learning',\n  domain: 'linkedin.com',\n  loginUrl: 'https://www.linkedin.com/login?session_redirect=%2Flearning%2F',\n  columns: ['public_id', 'plain_id', 'name'],\n  quickCheck: hasLinkedinSessionCookie,\n  verify: verifyLinkedinLearningIdentity,\n  poll: async (page) => {\n    if (!await hasLinkedinSessionCookie(page)) {\n      throw new AuthRequiredError('linkedin.com', 'Waiting for LinkedIn li_at cookie');\n    }\n    return verifyLinkedinLearningIdentity(page);\n  },\n});\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin-learning/auth.js#L27-L63","documentation":"If the probe result is none of the known kinds (auth/http/exception) but lacks ok:true, the command throws CommandExecutionError with the full JSON-serialized probe result. This is a defensive catch-all ensuring unexpected probe outputs are never silently ignored, and the serialized result aids debugging.","triggerScenarios":"page.evaluate returns an object without kind set (or a new/unexpected kind) and without ok:true — e.g. the probe's success path was not reached but it also didn't classify the failure, or an older/newer probe script version returns a different schema.","commonSituations":"Mixed versions of the CLI and its probe scripts; probe returned { ok: false } explicitly from an unhandled branch; a refactor of the evaluate script dropped the kind tagging.","solutions":["Inspect the JSON in the message to see exactly what the probe returned.","Update/reinstall the CLI so probe script and command handler versions match.","Fix the probe script so every exit path sets kind (auth/http/exception) or ok:true.","Add the missing branch to the probe's try/catch classification."],"exampleFix":"// before\nreturn { detail: 'unknown' }; // -> 'Unexpected LinkedIn Learning probe'\n// after\nreturn { kind: 'exception', detail: 'unknown' };","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isKnownProbeResult(r) {\n  return r && (r.ok === true || ['auth','http','exception'].includes(r.kind));\n}","tryCatchPattern":"try {\n  const identity = await verifyLinkedinLearningIdentity(page);\n} catch (e) {\n  if (e.message.startsWith('Unexpected LinkedIn Learning probe:')) {\n    const probe = JSON.parse(e.message.slice('Unexpected LinkedIn Learning probe:'.length));\n    console.error('probe returned unknown shape:', probe); // then update CLI/probe\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Keep the CLI and its probe scripts version-aligned (reinstall on updates).","Make every probe exit path set kind or ok:true.","Log unexpected results instead of swallowing them.","Add unit tests covering all probe return branches."],"tags":["linkedin","contract","debugging"],"backgroundTag":"unexpected-api-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}