{"record":{"id":"8fd29e3e967fb676","repo":"jackwener/OpenCLI","slug":"comment-text-is-required","errorCode":null,"errorMessage":"comment text is required","messagePattern":"comment text is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/utils.js","lineNumber":85,"sourceCode":"    const key = String(value ?? 'all').trim().toLowerCase();\n    if (!Object.prototype.hasOwnProperty.call(NOTIFICATION_TYPES, key)) {\n        throw new ArgumentError(\n            `unsupported notification type: ${value}`,\n            `Allowed: ${Object.keys(NOTIFICATION_TYPES).join(', ')}`,\n        );\n    }\n    return key;\n}\n\n// Comment text bound: TikTok rejects long comments at submit time.\n// We validate length + non-empty up-front so the adapter never tries to\n// paste an empty / overlong string into the contenteditable input.\nexport const COMMENT_TEXT_MAX = 150;\n\nexport function requireCommentText(value) {\n    const text = String(value ?? '').trim();\n    if (!text) {\n        throw new ArgumentError(\n            'comment text is required',\n            'Example: opencli tiktok comment <url> \"great video\"',\n        );\n    }\n    if (text.length > COMMENT_TEXT_MAX) {\n        throw new ArgumentError(\n            `comment text must be <= ${COMMENT_TEXT_MAX} characters (got ${text.length})`,\n            'TikTok rejects long comments at submit time; trim before retrying',\n        );\n    }\n    return text;\n}\n\n// Parses a TikTok video URL into {username, videoId, url}. Rejects bad\n// shapes up-front so we never `goto()` an arbitrary page and silently\n// pretend the click target was found. Both share-style links\n// (vm.tiktok.com/...) and bare video IDs are out of scope — callers must\n// pass the canonical /@user/video/id form.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/utils.js#L67-L103","documentation":"requireCommentText trims the provided text and throws this ArgumentError when it is empty, because pasting an empty string into TikTok's contenteditable comment box would silently do nothing. The validator also enforces a maximum length (COMMENT_TEXT_MAX = 150) in the same pass.","triggerScenarios":"Passing an empty string or only whitespace ('   ') as the comment argument; an unset shell variable expanding to ''; stripping/transforming the text so it becomes empty before validation; quoting mistakes where the argument is lost entirely.","commonSituations":"Batch scripts generating comments where some rows have blank text; forgetting the quoted argument (opencli tiktok comment <url> with no text); templates with unfilled placeholders leaving empty strings.","solutions":["Pass a non-empty quoted comment, e.g. opencli tiktok comment <url> \"great video\".","Keep text at or under 150 characters (COMMENT_TEXT_MAX).","Guard scripts against blank values: skip the call or substitute real text when the variable is empty.","Trim and check truthiness before invoking in code."],"exampleFix":"// before\nconst text = row.comment || ''; // may be empty\nawait cli.tiktok.comment(url, text); // throws\n// after\nconst text = (row.comment || '').trim();\nif (!text) { console.warn('skipping empty comment'); return; }\nawait cli.tiktok.comment(url, text.slice(0, 150));","handlingStrategy":"validation","validationCode":"const COMMENT_TEXT_MAX = 150;\nfunction assertCommentText(v) {\n  const text = String(v ?? '').trim();\n  if (!text) throw new Error('comment text is required');\n  if (text.length > COMMENT_TEXT_MAX) throw new Error(`comment text must be <= ${COMMENT_TEXT_MAX} chars`);\n  return text;\n}\nassertCommentText(commentArg);","typeGuard":null,"tryCatchPattern":"try {\n  await cli.tiktok.comment(url, text);\n} catch (e) {\n  if (/comment text is required/.test(e.message)) {\n    console.error('Pass a non-empty quoted comment: opencli tiktok comment <url> \"great video\"');\n  } else throw e;\n}","preventionTips":["Always pass the comment as a quoted shell argument so it is not dropped","Trim and check truthiness of generated comment text before calling","Keep comments <= 150 characters (COMMENT_TEXT_MAX)","In batch scripts, skip rows with blank comment text instead of invoking the CLI"],"tags":["validation","argument-error","cli","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}