{"record":{"id":"987cceb4ff283c6d","repo":"jackwener/OpenCLI","slug":"label-failed","errorCode":null,"errorMessage":"${label} failed","messagePattern":"(.+?) failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/salesnav-message.js","lineNumber":166,"sourceCode":"    } catch (e) {\n      return ['error', 0, null, '', 'fetch failed: ' + ((e && e.message) || String(e))];\n    }\n  })()`;\n}\n\nfunction requireFetchResult(result, label, { requireJson = true } = {}) {\n  if (Array.isArray(result)) {\n    const [kind, status, json, text, error] = result;\n    result = {\n      authRequired: kind === 'auth',\n      error: kind === 'error' ? error || `HTTP ${status}` : '',\n      status,\n      json,\n      text,\n    };\n  }\n  if (result?.authRequired) throw new AuthRequiredError(LINKEDIN_DOMAIN, `${label} auth failed.`);\n  if (result?.error) throw new CommandExecutionError(`${label} failed`, result.error);\n  if (!result || typeof result !== 'object' || Array.isArray(result)) {\n    throw new CommandExecutionError(`${label} returned malformed response`);\n  }\n  if (requireJson && (!result.json || typeof result.json !== 'object' || Array.isArray(result.json))) {\n    throw new CommandExecutionError(`${label} returned malformed response`, 'missing_json');\n  }\n  return result;\n}\n\nfunction salesPageShowsSentMessage(text, recipientName) {\n  const normalizedText = normalizeWhitespace(text);\n  const firstName = normalizeWhitespace(recipientName).split(' ')[0];\n  return normalizedText.includes('You sent a Sales Navigator message')\n    && (!firstName || normalizedText.includes(firstName));\n}\n\nasync function getCsrf(page) {\n  const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/salesnav-message.js#L148-L184","documentation":"When the fetch response body contains an error field, requireFetchResult wraps it in CommandExecutionError with message '${label} failed' and the upstream error as detail. This is LinkedIn's Sales Navigator API reporting a request-level failure (not auth, not malformed output).","triggerScenarios":"profileResult/creditsResult/sendResult/creditsAfterResult receive a response whose JSON has an error property — e.g. API rejects the createMessage payload, invalid recipient urn, or server-side 4xx surfaced inside the body.","commonSituations":"Messaging a recipient with InMail restriction; expired credit grant endpoint shape change; LinkedIn API contract drift after a site update; invalid subject/body constraints the API rejects server-side.","solutions":["Read the error detail (second argument) — it carries LinkedIn's upstream message","Retry with a different, fully-resolved recipient urn (authType/authToken present)","Re-check payload constraints (subject <=200 chars, body <=1900) before calling","Re-verify the Sales Navigator API response shape after LinkedIn UI updates"],"exampleFix":"// before\nawait sendInMail(page, { subject: longSubject, body });\n// after\nif (subject.length > 200) subject = subject.slice(0, 200);\nawait sendInMail(page, { subject, body });","handlingStrategy":"try-catch","validationCode":"// validate payload before calling\nif (!recipientUrn?.startsWith('urn:li:fs_salesProfile:')) throw new Error('bad recipient');\nif (subject.length > 200 || body.length > 1900) throw new Error('payload too long');","typeGuard":"const isApiErrorBody = (result) => result != null && typeof result === 'object' && !Array.isArray(result) && typeof result.error === 'string' && result.error.length > 0;","tryCatchPattern":"try {\n  await sendMessage(...);\n} catch (err) {\n  if (err instanceof CommandExecutionError && / failed$/.test(err.message)) {\n    console.error('LinkedIn said:', err.detail ?? err.cause);\n  } else throw err;\n}","preventionTips":["Log the error detail — it contains LinkedIn's upstream reason","Respect payload limits (subject 200, body 1900 chars)","Re-verify API response shapes after LinkedIn UI updates","Retry with a fully-resolved recipient urn"],"tags":["api","linkedin","sales-navigator","upstream-error"],"backgroundTag":"api-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}