laurent22/joplin · error · Error
Error! Destination already exists
Error message
Error! Destination already exists
What it means
Thrown by `tarCreate` when the destination tar file (resolved from `options.cwd` + `options.file`) already exists, before packing begins. This prevents silently overwriting a previous backup. It is a pure precondition check on the resolved output path.
Source
Thrown at packages/app-mobile/utils/fs-driver/tarCreate.ts:26
const logger = Logger.create('fs-driver-rn');
export interface TarCreateOptions {
cwd: string;
file: string;
}
// TODO: Support glob patterns, which are currently supported by the
// node fsDriver.
const tarCreate = async (options: TarCreateOptions, filePaths: string[]) => {
// Choose a default cwd if not given
const cwd = options.cwd ?? shim.fsDriver().getAppDirectoryPath();
const file = resolve(cwd, options.file);
const fsDriver = shim.fsDriver();
if (await fsDriver.exists(file)) {
throw new Error('Error! Destination already exists');
}
const pack = tarStreamPack();
const errors: Error[] = [];
pack.addListener('error', error => {
logger.error(`Tar error: ${error}`);
errors.push(error);
});
for (const path of filePaths) {
const absPath = resolve(cwd, path);
const stat = await fsDriver.stat(absPath);
const sizeBytes: number = stat.size;
const entry = pack.entry({ name: path, size: sizeBytes }, (error) => {
if (error) {
logger.error(`Tar error: ${error}`);View on GitHub (pinned to 2654b33620)
Solutions
- Delete or rename the existing destination before calling `tarCreate`.
- Use a timestamped filename so each run produces a unique archive.
- Pre-check: `if (await fsDriver.exists(file)) await fsDriver.remove(file);`.
Example fix
// before
await tarCreate({ cwd, file: 'backup.tar' }, filePaths);
// after
const file = resolve(cwd, 'backup.tar');
if (await shim.fsDriver().exists(file)) {
await shim.fsDriver().remove(file);
}
await tarCreate({ cwd, file: 'backup.tar' }, filePaths); Defensive patterns
Strategy: validation
Validate before calling
const dest = resolve(options.cwd ?? shim.fsDriver().getAppDirectoryPath(), options.file);
if (await shim.fsDriver().exists(dest)) {
await shim.fsDriver().remove(dest);
}
await tarCreate(options, filePaths); Type guard
null
Try / catch
try {
await tarCreate(options, filePaths);
} catch (error) {
if (/Destination already exists/i.test(error.message)) {
await shim.fsDriver().remove(resolve(options.cwd ?? shim.fsDriver().getAppDirectoryPath(), options.file));
return tarCreate(options, filePaths);
}
throw error;
} Prevention
- Use timestamped output filenames to avoid collisions.
- Delete the prior archive before re-running a backup.
- Pre-check existence at the resolved path, not the relative one.
When it happens
Trigger: Calling `tarCreate(options, filePaths)` where `resolve(cwd, options.file)` resolves to an existing file. Typically when creating a backup with a fixed filename that already exists from a prior run.
Common situations: Repeated backup runs that reuse the same filename; manual copies left in the output directory; a previous run succeeded and the caller forgot to delete the old archive.
Related errors
- tarExtract: Source file does not exist
- Extracting ${outPath} would overwrite
- Unsupported file system entity type: ${header.type}
- No model found at path: ${JSON.stringify(modelFolderPath)}
- Model not found at path ${modelPath}
AI-assisted analysis of laurent22/joplin@2654b33620 (2026-08-12).
Data as JSON: /api/errors/dee094c458e7e897.
Report an issue: GitHub.