jackwener/OpenCLI · error · CommandExecutionError

抖音上传提交缺少 SessionKey

Error message

抖音上传提交缺少 SessionKey

What it means

commitVideoUploadInner requires uploadInfo.session_key to commit the finished upload via CommitUploadInner; this guard throws when session_key is missing/empty on the uploadInfo object. Without SessionKey the server cannot correlate the committed upload, so the library fails before making the network call.

Source

Thrown at clis/douyin/_shared/vod-upload.js:173

  const videoId = payload?.Result?.Vid || uploadNode?.Vid;
  const sessionKey = uploadNode?.SessionKey ?? storeInfo?.SessionKey ?? payload?.Result?.SessionKey;
  if (!uploadNode?.UploadHost || !storeInfo?.StoreUri || !storeInfo?.Auth || !videoId || !sessionKey) {
    throw new CommandExecutionError(`申请抖音上传地址响应缺少必要字段: ${JSON.stringify(payload).slice(0, 500)}`);
  }
  return {
    video_id: videoId,
    tos_upload_url: `https://${uploadNode.UploadHost}/${storeInfo.StoreUri}`,
    auth: storeInfo.Auth,
    session_key: sessionKey,
    upload_header: uploadNode.UploadHeader ?? {},
    user_id: credentials.user_id ?? '',
  };
}


export async function commitVideoUploadInner(uploadInfo, credentials) {
  if (!uploadInfo?.session_key) {
    throw new CommandExecutionError('抖音上传提交缺少 SessionKey');
  }
  const params = new URLSearchParams({
    Action: 'CommitUploadInner',
    Version: '2020-11-19',
    SpaceName: VOD_SPACE_NAME,
  });
  const url = `${VOD_UPLOAD_HOST}?${params.toString()}`;
  const body = JSON.stringify({ SessionKey: uploadInfo.session_key });
  const headers = computeAws4Headers(url, credentials, {
    method: 'POST',
    body,
    headers: { 'content-type': 'application/json;charset=UTF-8' },
  });
  const res = await fetch(url, { method: 'POST', headers, body, signal: AbortSignal.timeout(30000) });
  const text = await res.text();
  let payload;
  try {
    payload = JSON.parse(text);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure uploadInfo is the full object returned by applyVideoUploadInner, which always sets session_key.
  2. Log the uploadInfo keys before committing to see which fields are missing.
  3. Fix upstream code that reconstructs or filters uploadInfo and accidentally drops session_key.
  4. If applyVideoUploadInner threw earlier, abort the pipeline instead of committing with a partial object.
  5. Add your own precondition check on uploadInfo.session_key before calling commit.

Example fix

// before
await commitVideoUploadInner({ video_id: vid }, credentials); // missing session_key
// after
const uploadInfo = await applyVideoUploadInner(fileSize, credentials); // full object incl. session_key
await commitVideoUploadInner(uploadInfo, credentials);
Defensive patterns

Strategy: validation

Validate before calling

function isCommittable(uploadInfo) {
  return Boolean(uploadInfo && typeof uploadInfo.session_key === 'string' && uploadInfo.session_key.length > 0);
}
// before committing:
if (!isCommittable(uploadInfo)) throw new Error('uploadInfo 缺少 session_key,请检查 apply 阶段结果');

Type guard

null

Try / catch

try {
  await commitVideoUploadInner(uploadInfo, creds);
} catch (e) {
  if (/缺少 SessionKey/.test(e.message)) {
    console.error('uploadInfo keys:', Object.keys(uploadInfo ?? {}));
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling commitVideoUploadInner with an uploadInfo object that lacks session_key — e.g. it was built manually, or came from a code path that skipped/failed applyVideoUploadInner's field extraction, or the property was renamed.

Common situations: Custom pipeline code constructing uploadInfo by hand and forgetting session_key; downstream code destructuring applyVideoUploadInner's return and dropping fields; an earlier 'missing required fields' error handled loosely, letting a partial object flow through.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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