alyssaxuu/screenity · error · Error

Invalid reuse object: must have both videoId and mediaId

Error message

Invalid reuse object: must have both videoId and mediaId

What it means

uploader.initialize() accepts an optional `reuse` object so the caller can attach the upload to an already-created Bunny video instead of creating a new one. When `reuse` is truthy but is missing either `videoId` or `mediaId` (the two identifiers the uploader needs to target the existing video), the constructor-time contract is broken and initialize() throws immediately before doing any network work. This is a caller-supplied-input validation error, not a network or auth failure.

Source

Thrown at src/pages/CloudRecorder/bunnyTusUploader.js:869

        projectId,
        sceneId,
        type,
        width,
        height,
      });
      this.fingerprint = fingerprint;

      const resumeJournal = await this.getResumeJournal({
        projectId,
        sceneId,
        type,
        fingerprint,
        reuse,
      });

      if (reuse) {
        if (!reuse.videoId || !reuse.mediaId) {
          throw new Error(
            "Invalid reuse object: must have both videoId and mediaId",
          );
        }
        this.videoId = reuse.videoId;
        this.mediaId = reuse.mediaId;
      } else if (resumeJournal?.videoId && resumeJournal?.mediaId) {
        this.initializedFromResume = true;
        this.videoId = resumeJournal.videoId;
        this.mediaId = resumeJournal.mediaId;
        this.uploadUrl = resumeJournal.uploadUrl || null;
        this.offset = resumeJournal.offset || 0;
        this.totalBytes = resumeJournal.totalBytes || 0;
        this.journalKey =
          resumeJournal.key || this.journalKey || this.getJournalKey(this.mediaId);
        this.journalLookupKey = resumeJournal.lookupKey || this.journalLookupKey;
        if (!this.sessionId && resumeJournal.sessionId) {
          this.sessionId = resumeJournal.sessionId;
        }

View on GitHub (pinned to 512606387b)

Solutions

  1. Fix the caller to pass both reuse.videoId and reuse.mediaId (non-empty strings) whenever reuse is provided.
  2. If reuse cannot be fully populated, omit the reuse property entirely so initialize() falls back to journal/video-map lookup or creates a fresh Bunny video.
  3. Inspect where the reuse object was built and log it; likely one field is undefined because the upstream API/storage shape changed.

Example fix

// before
await uploader.initialize({ projectId, sceneId, type, reuse: videoInfo });
// after
const reuse = videoInfo?.videoId && videoInfo?.mediaId ? { videoId: videoInfo.videoId, mediaId: videoInfo.mediaId } : undefined;
await uploader.initialize({ projectId, sceneId, type, reuse });
Defensive patterns

Strategy: validation

Validate before calling

if (reuse && !(typeof reuse.videoId === 'string' && reuse.videoId && typeof reuse.mediaId === 'string' && reuse.mediaId)) {
  throw new TypeError('reuse must include both videoId and mediaId, or be omitted');
}

Type guard

function isValidReuse(reuse) {
  return reuse == null || (typeof reuse.videoId === 'string' && reuse.videoId.length > 0 && typeof reuse.mediaId === 'string' && reuse.mediaId.length > 0);
}

Try / catch

try {
  await uploader.initialize({ projectId, sceneId, type, reuse });
} catch (err) {
  if (String(err?.message).includes('Invalid reuse object')) {
    // fall back to fresh/journal init
    await uploader.initialize({ projectId, sceneId, type });
  } else throw err;
}

Prevention

When it happens

Trigger: Calling initialize({..., reuse}) where reuse is truthy but reuse.videoId or reuse.mediaId is undefined/null/empty string — e.g. reuse was built from an API response field that was absent, or a partially-hydrated object was passed in.

Common situations: Passing a stored video-map entry where only one of the two IDs survived serialization; destructuring a server response where the API changed shape and only videoId came back; passing `{}` or a truthy-but-incomplete placeholder to force reuse semantics.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of alyssaxuu/screenity@512606387b (2026-09-02). Data as JSON: /api/errors/39e89d5d768ae221. Report an issue: GitHub.