{"record":{"id":"41043ed93a67b272","repo":"jackwener/OpenCLI","slug":"subject-is-required","errorCode":null,"errorMessage":"--subject is required","messagePattern":"--subject is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/salesnav-message.js","lineNumber":92,"sourceCode":"function profileApiUrl(recipient) {\n  if (!recipient?.profileId || !recipient?.authType || !recipient?.authToken) return '';\n  const key = `(profileId:${recipient.profileId},authType:${recipient.authType},authToken:${recipient.authToken})`;\n  return `https://www.linkedin.com/sales-api/salesApiProfiles/${key}?decoration=${encodeRestliDecoration(PROFILE_DECO)}`;\n}\n\nfunction randomTrackingId() {\n  const bytes = new Uint8Array(8);\n  if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(bytes);\n  else for (let i = 0; i < bytes.length; i += 1) bytes[i] = Math.floor(Math.random() * 256);\n  return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n}\n\nfunction buildCreateMessagePayload({ recipientUrn, subject, body, trackingId = randomTrackingId(), copyToCrm = false }) {\n  const cleanRecipient = normalizeWhitespace(recipientUrn);\n  if (!parseSalesProfileUrn(cleanRecipient)) throw new ArgumentError('--recipient must resolve to a Sales Navigator lead urn');\n  const cleanSubject = normalizeWhitespace(subject);\n  const cleanBody = String(body ?? '').trim();\n  if (!cleanSubject) throw new ArgumentError('--subject is required');\n  if (!cleanBody) throw new ArgumentError('--body is required');\n  if (cleanSubject.length > 200) throw new ArgumentError('--subject must be 200 characters or fewer');\n  if (cleanBody.length > 1900) throw new ArgumentError('--body must be 1900 characters or fewer');\n  return {\n    createMessageRequest: {\n      recipients: [cleanRecipient],\n      subject: cleanSubject,\n      body: cleanBody,\n      copyToCrm: Boolean(copyToCrm),\n      trackingId,\n    },\n  };\n}\n\nfunction extractRemainingCredits(json) {\n  const elements = Array.isArray(json?.elements) ? json.elements : [];\n  const inmailGrant = elements.find((el) => el?.type === 'LSS_INMAIL' && Number.isInteger(el.value));\n  if (inmailGrant) return inmailGrant.value;","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/salesnav-message.js#L74-L110","documentation":"buildCreateMessagePayload requires a non-empty subject after whitespace normalization; an empty subject cannot be sent via the Sales Navigator create-message API, so it throws ArgumentError.","triggerScenarios":"--subject is omitted, empty string, or only whitespace/non-breaking spaces (normalizeWhitespace yields '').","commonSituations":"Forgetting the --subject flag; shell quoting issues that drop the value; pasting a subject of only spaces; programmatic calls passing undefined in the subject field.","solutions":["Provide --subject \"Your subject line\".","Check quoting/escaping in your shell so the value isn't lost.","Trim/pad the subject to at least one non-whitespace character before calling."],"exampleFix":"// before\nlinkedin salesnav-message --recipient \"...\" --body \"hi\"\n// after\nlinkedin salesnav-message --recipient \"...\" --subject \"Quick intro\" --body \"hi\"","handlingStrategy":"validation","validationCode":"if (!args.subject || !String(args.subject).trim()) throw new Error('pass a non-empty --subject');","typeGuard":"function hasSubject(a) { return typeof a.subject === 'string' && a.subject.trim().length > 0; }","tryCatchPattern":"try { await sendMessage(args); } catch (e) { if (/--subject is required/.test(e.message)) { args.subject = '(no subject)'; /* retry with default */ } else throw e; }","preventionTips":["Include --subject in every salesnav-message invocation.","Validate CLI args in a wrapper script before running.","Beware quoting issues that drop the subject value.","Provide a default subject in templates."],"tags":["argument-validation","cli","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}