jackwener/OpenCLI · error · ArgumentError

comment text is required

Error message

comment text is required

What it means

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.

Source

Thrown at clis/tiktok/utils.js:85

    const key = String(value ?? 'all').trim().toLowerCase();
    if (!Object.prototype.hasOwnProperty.call(NOTIFICATION_TYPES, key)) {
        throw new ArgumentError(
            `unsupported notification type: ${value}`,
            `Allowed: ${Object.keys(NOTIFICATION_TYPES).join(', ')}`,
        );
    }
    return key;
}

// Comment text bound: TikTok rejects long comments at submit time.
// We validate length + non-empty up-front so the adapter never tries to
// paste an empty / overlong string into the contenteditable input.
export const COMMENT_TEXT_MAX = 150;

export function requireCommentText(value) {
    const text = String(value ?? '').trim();
    if (!text) {
        throw new ArgumentError(
            'comment text is required',
            'Example: opencli tiktok comment <url> "great video"',
        );
    }
    if (text.length > COMMENT_TEXT_MAX) {
        throw new ArgumentError(
            `comment text must be <= ${COMMENT_TEXT_MAX} characters (got ${text.length})`,
            'TikTok rejects long comments at submit time; trim before retrying',
        );
    }
    return text;
}

// Parses a TikTok video URL into {username, videoId, url}. Rejects bad
// shapes up-front so we never `goto()` an arbitrary page and silently
// pretend the click target was found. Both share-style links
// (vm.tiktok.com/...) and bare video IDs are out of scope — callers must
// pass the canonical /@user/video/id form.

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty quoted comment, e.g. opencli tiktok comment <url> "great video".
  2. Keep text at or under 150 characters (COMMENT_TEXT_MAX).
  3. Guard scripts against blank values: skip the call or substitute real text when the variable is empty.
  4. Trim and check truthiness before invoking in code.

Example fix

// before
const text = row.comment || ''; // may be empty
await cli.tiktok.comment(url, text); // throws
// after
const text = (row.comment || '').trim();
if (!text) { console.warn('skipping empty comment'); return; }
await cli.tiktok.comment(url, text.slice(0, 150));
Defensive patterns

Strategy: validation

Validate before calling

const COMMENT_TEXT_MAX = 150;
function assertCommentText(v) {
  const text = String(v ?? '').trim();
  if (!text) throw new Error('comment text is required');
  if (text.length > COMMENT_TEXT_MAX) throw new Error(`comment text must be <= ${COMMENT_TEXT_MAX} chars`);
  return text;
}
assertCommentText(commentArg);

Try / catch

try {
  await cli.tiktok.comment(url, text);
} catch (e) {
  if (/comment text is required/.test(e.message)) {
    console.error('Pass a non-empty quoted comment: opencli tiktok comment <url> "great video"');
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/8fd29e3e967fb676. Report an issue: GitHub.