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
- Delete or move the existing outputRoot/illust/{illust_id} directory if you want a fresh download
- Use a different --output root for the new run so paths don't collide
- Add a resume/skip mode: catch this error and treat existing directories as already-complete downloads
- 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
- Give each run a fresh or versioned output root (e.g. output-YYYYMMDD) to avoid collisions
- Build an idempotent runner that skips ids whose illust/{id} directory already exists
- Inspect partial downloads after an interrupted run and complete or remove them before re-running
- Archive/move old downloads rather than re-pointing outputRoot at the same tree
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
- Refusing to overwrite existing Pixiv download: ${destPath}
- Verify command returned no metric for baseline
- File not found: ${path}
- File must be a readable text file: ${path}
- File could not be read: ${path}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4ab3ab667c6e4179.
Report an issue: GitHub.