stablyai/orca · error · Error

Could not generate a unique name for '${originalName}' after

Error message

Could not generate a unique name for '${originalName}' after ${counter} attempts

What it means

Thrown by deconflictName when it cannot find a unique name after trying 9998 candidates (counter 2 through 9999). The function appends ' copy', ' copy 2', ..., ' copy 9999' and checks both filesystem existence and an in-batch reserved set. This is an extremely unlikely fallback meant to guarantee termination.

Source

Thrown at src/main/ipc/filesystem-mutations.ts:794

  const stem = hasMeaningfulExt ? originalName.slice(0, dotIndex) : originalName
  const ext = hasMeaningfulExt ? originalName.slice(dotIndex) : ''

  let candidate = `${stem} copy${ext}`
  if (!(await nameExists(destDir, candidate)) && !reservedNames.has(candidate)) {
    return candidate
  }

  let counter = 2
  while (counter < 10000) {
    candidate = `${stem} copy ${counter}${ext}`
    if (!(await nameExists(destDir, candidate)) && !reservedNames.has(candidate)) {
      return candidate
    }
    counter += 1
  }

  // Extremely unlikely fallback
  throw new Error(
    `Could not generate a unique name for '${originalName}' after ${counter} attempts`
  )
}

async function nameExists(dir: string, name: string): Promise<boolean> {
  try {
    await lstat(join(dir, name))
    return true
  } catch (error) {
    if (isENOENT(error)) {
      return false
    }
    throw error
  }
}

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Clear or reduce the number of similarly-named files in the destination directory.
  2. Choose a different destination directory with fewer name collisions.
  3. If importing a batch, ensure source files have distinct names or import in smaller batches.

Example fix

// before: import into /dest which has 9999+ "report copy N.csv" files
// after: clean up or use a fresh directory
//   rm /dest/'report copy '*.csv
//   or: import into /dest/fresh-batch/
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await importLocalSource(sourcePath, destDir)
} catch (error) {
  if (error instanceof Error && error.message.includes('Could not generate a unique name')) {
    showUserError('Too many name collisions in the destination. Use a different folder or clean up existing copies.')
    return
  }
  throw error
}

Prevention

When it happens

Trigger: The destination directory already contains 9999+ files with names matching the pattern 'stem copy N.ext' for the same stem, or the reservedNames set (tracking in-batch deconfliction) covers all 9998 candidates. The loop exits at counter = 10000 without finding a free name.

Common situations: Importing into a directory with thousands of similarly-named files from repeated copy operations. A bug or loop in the caller that generates an enormous reservedNames set. Importing a very large batch where many source files have identical names.

Related errors


AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12). Data as JSON: /api/errors/677ef6e6b75b4b29. Report an issue: GitHub.