jackwener/OpenCLI · error · ArgumentError

不支持的${label}格式: ${ext}(支持 ${Array.from(allowedExts).join('/'

Error message

不支持的${label}格式: ${ext}(支持 ${Array.from(allowedExts).join('/')})

What it means

requireFilePath checks the resolved path's extension against the allowed set (.mp4/.mov/.avi/.webm) and throws ArgumentError when it does not match. WeChat Channels only accepts video uploads, so unsupported formats are rejected before any browser automation begins.

Source

Thrown at clis/wechat-channels/publish.js:77

async function evalPage(page, script) {
  return unwrapEvaluateResult(await page.evaluate(script));
}

function requireFilePath(filePath, label, allowedExts) {
  const resolved = path.resolve(String(filePath));
  let stat;
  try {
    stat = fs.statSync(resolved);
  } catch {
    throw new ArgumentError(`${label}文件不存在: ${resolved}`);
  }
  if (!stat.isFile()) {
    throw new ArgumentError(`${label}路径不是文件: ${resolved}`);
  }
  const ext = path.extname(resolved).toLowerCase();
  if (!allowedExts.has(ext)) {
    throw new ArgumentError(`不支持的${label}格式: ${ext}(支持 ${Array.from(allowedExts).join('/')})`);
  }
  return resolved;
}

function parseTimeoutSeconds(raw) {
  const timeout = raw == null || raw === '' ? 600 : Number(raw);
  if (!Number.isInteger(timeout) || timeout < 30) {
    throw new ArgumentError('--timeout must be an integer >= 30 seconds');
  }
  return timeout;
}

function parseScheduleDate(raw) {
  if (!raw) return null;
  const dt = typeof raw === 'number'
    ? new Date(raw < 1e12 ? raw * 1000 : raw)
    : new Date(String(raw));
  if (Number.isNaN(dt.getTime())) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert the video to MP4 (e.g. ffmpeg -i input.mkv -c copy output.mp4).
  2. Use one of the supported extensions: .mp4, .mov, .avi, .webm.
  3. Rename only if the container actually matches the extension (renaming .mkv to .mp4 will fail at upload).

Example fix

// before
node publish.js --video screen-recording.mkv
// after
ffmpeg -i screen-recording.mkv -c:v libx264 -c:a aac screen-recording.mp4
node publish.js --video screen-recording.mp4
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = new Set(['.mp4', '.mov', '.avi', '.webm']);
const ext = require('path').extname(videoPath).toLowerCase();
if (!ALLOWED.has(ext)) {
  throw new Error(`Unsupported extension ${ext}; convert to .mp4 first`);
}

Type guard

function hasAllowedVideoExt(p) {
  return ['.mp4', '.mov', '.avi', '.webm'].includes(require('path').extname(p).toLowerCase());
}

Try / catch

try {
  await publish({ videoPath });
} catch (e) {
  if (/不支持的.*格式/.test(e.message)) {
    console.error('Convert with: ffmpeg -i in.<ext> -c copy in.mp4');
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a video with an extension outside {.mp4,.mov,.avi,.webm} (e.g. .mkv, .flv, .ts, .m4v) or a file with no extension via videoPath/requireFilePath.

Common situations: Users exporting MKV from OBS; uppercase extensions are fine (lowercased) but formats like .m4v or .wmv are not; generated temp files missing extensions.

Related errors


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