jackwener/OpenCLI · error · CommandExecutionError

Refusing to overwrite existing Pixiv download: ${destPath}

Error message

Refusing to overwrite existing Pixiv download: ${destPath}

What it means

prepareNovelFile builds the destination <outputDir>/<novelId>.<format> and refuses to proceed if any filesystem entry (file, symlink, directory) already exists at that path (lstat succeeds). The download is deliberately non-destructive: existing Pixiv downloads are never overwritten, so the user gets a clear error instead of silent data loss.

Source

Thrown at clis/pixiv/novel-download-utils.js:160

    `User ID: ${body.userId}`,
    `Novel ID: ${body.id}`,
    `URL: ${url}`,
    body.createdDate ? `Created: ${body.createdDate}` : '',
    tags ? `Tags: ${tags}` : '',
    body.wordCount != null ? `Words: ${body.wordCount}` : '',
    body.bookmarkCount != null ? `Bookmarks: ${body.bookmarkCount}` : '',
    '',
    body.content,
    '',
  ].filter(line => line !== '').join('\n');
}

export function prepareNovelFile(body, output, format) {
  const outputDir = normalizePixivOutputRoot(output, './pixiv-downloads/novels');
  const filename = `${body.id}.${format}`;
  const destPath = path.join(outputDir, filename);
  if (pixivPathEntryExists(destPath)) {
    throw new CommandExecutionError(`Refusing to overwrite existing Pixiv download: ${destPath}`);
  }
  const createdDirs = [];
  for (let cursor = outputDir; !fs.existsSync(cursor); cursor = path.dirname(cursor)) {
    createdDirs.push(cursor);
    if (path.dirname(cursor) === cursor) break;
  }
  return {
    kind: 'novel',
    outputDir,
    createdDirs,
    destPath,
    content: formatNovelContent(body, format),
  };
}

export function writeNovelFile(body, output, format) {
  return commitNovelFile(prepareNovelFile(body, output, format));
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Delete or move the existing file at the reported path if overwriting is intended, then re-run.
  2. Use a different --output directory (or include date/batch in the path) for repeat runs.
  3. Check pixivPathEntryExists yourself beforehand and skip or rename when the destination exists.
  4. Clear stale partial downloads from crashed runs before retrying the batch.

Example fix

// before
await writeNovelFile(body, './downloads'); // 12345.txt exists
// after
import { pixivPathEntryExists } from './novel-download-utils.js';
if (pixivPathEntryExists('./downloads/12345.txt')) {
  console.log('already downloaded, skipping');
} else {
  await writeNovelFile(body, './downloads');
}
Defensive patterns

Strategy: try-catch

Validate before calling

import fs from 'node:fs';
import path from 'node:path';
const dest = path.join(outputDir, `${body.id}.${format}`);
if (fs.existsSync(dest)) {
  console.log(`Skipping ${dest}: already downloaded`);
}

Try / catch

try {
  await downloadNovel(id, { output });
} catch (e) {
  if (e.message.startsWith('Refusing to overwrite existing Pixiv download')) {
    console.log('Already downloaded — skipping.');
  } else throw e;
}

Prevention

When it happens

Trigger: Downloading the same novel twice with the same --output and --format; a leftover partial or previously downloaded file with the same <id>.txt/<id>.md name; a directory named like the target file occupying the path.

Common situations: Re-running a batch script without cleaning the output folder; switching formats back and forth and re-downloading; restoring a backup over an existing tree; id collision from a shared download directory.

Related errors


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