jackwener/OpenCLI · error · CommandExecutionError

Refusing to overwrite existing Pixiv download: ${finalPath}

Error message

Refusing to overwrite existing Pixiv download: ${finalPath}

What it means

The computed destination directory outputRoot/illust/{illust_id} already exists on disk, so prepareIllustPlan refuses to re-download and overwrite it, throwing CommandExecutionError with the full path. This protects previously downloaded artwork from being clobbered by a re-run of the bookmark download.

Source

Thrown at clis/pixiv/bookmark-download.js:72

  if (!Array.isArray(pages)) {
    throw new CommandExecutionError('Pixiv pages API returned malformed payload');
  }
  if (pages.length === 0) {
    throw new EmptyResultError('pixiv bookmark-download', `No images found for illustration ${row.illust_id}.`);
  }
  const files = pages.map((entry, index) => {
    if (!entry || Array.isArray(entry) || typeof entry !== 'object' || !entry.urls || Array.isArray(entry.urls) || typeof entry.urls !== 'object') {
      throw new CommandExecutionError(`Pixiv illustration ${row.illust_id} returned malformed page ${index + 1}`);
    }
    const parsed = parsePixivImageUrl(entry.urls.original || entry.urls.regular, `Pixiv illustration ${row.illust_id} page ${index + 1}`);
    return {
      ...parsed,
      filename: `${row.illust_id}_p${index}${parsed.extension}`,
    };
  });
  const finalPath = path.join(outputRoot, 'illust', row.illust_id);
  if (pixivPathEntryExists(finalPath)) {
    throw new CommandExecutionError(`Refusing to overwrite existing Pixiv download: ${finalPath}`);
  }
  const createdDirs = [];
  for (let cursor = path.dirname(finalPath); !fs.existsSync(cursor); cursor = path.dirname(cursor)) {
    createdDirs.push(cursor);
    if (path.dirname(cursor) === cursor) break;
  }
  return { kind: 'illust', illustId: row.illust_id, finalPath, files, createdDirs };
}

function validateImageDownload(result, file) {
  if (!result || typeof result !== 'object' || result.success !== true || !Number.isSafeInteger(result.size) || result.size <= 0) {
    throw new CommandExecutionError(`Pixiv image download failed: ${result?.error || 'invalid download result'}`);
  }
  const final = parsePixivImageUrl(result.finalUrl, 'Pixiv image download');
  if (final.contentType !== file.contentType || result.contentType !== file.contentType) {
    throw new CommandExecutionError(`Pixiv image download returned unexpected content type for ${file.filename}`);
  }
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Delete or move the existing outputRoot/illust/{illust_id} directory if you want a fresh download
  2. Use a different --output root for the new run so paths don't collide
  3. Add a resume/skip mode: catch this error and treat existing directories as already-complete downloads
  4. Check the existing directory's contents first — it may be a partial download you can complete manually instead of re-downloading

Example fix

// before
await bookmarkDownloadCli({ outputRoot: './downloads' });
// after
const fs = require('fs');
const target = './downloads/illust/' + illustId;
if (fs.existsSync(target)) { console.log('already downloaded, skipping'); } else { await bookmarkDownloadCli({ outputRoot: './downloads' }); }
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
const finalPath = path.join(outputRoot, 'illust', row.illust_id);
if (fs.existsSync(finalPath)) {
  console.log(`skipping ${row.illust_id}: already exists at ${finalPath}`);
  return;
}

Type guard

function isSafeToDownload(outputRoot, illustId) {
  const finalPath = require('path').join(outputRoot, 'illust', String(illustId));
  return !require('fs').existsSync(finalPath);
}

Try / catch

try {
  await bookmarkDownload(row);
} catch (err) {
  if (err instanceof CommandExecutionError && err.message.startsWith('Refusing to overwrite existing Pixiv download')) {
    console.warn(`${row.illust_id} already downloaded — skipping`);
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Running bookmark-download twice against the same bookmark set, or a previous run partially completed and left an illust/{id} directory behind, and pixivPathEntryExists(finalPath) therefore returns true.

Common situations: Re-running a cron/script without clearing the output directory; resuming an interrupted sync where the directory was created before files finished; pointing outputRoot at a location that already holds an older download of the same illustration.

Related errors


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