schollz/croc · warning

Choose at least one file

Error message

Choose at least one file

What it means

prepareStoredFiles() rejects an empty selection up front: a stored transfer must contain at least one file. The check runs before any hashing or limits, so it is a pure input-validation error signaling the caller (usually UI state) allowed a submit with nothing picked.

Source

Thrown at web/src/protocol/stored.ts:295

    for (;;) {
      checkAbort(signal);
      const { done, value } = await reader.read();
      if (done) break;
      await engine.sha256Update(handle, value);
    }
    return await engine.sha256Final(handle);
  } finally {
    reader.releaseLock();
  }
}

export async function prepareStoredFiles(
  selected: File[],
  settings: StoredSettings,
  callbacks: { onStatus?(status: string): void } = {},
  signal?: AbortSignal,
) {
  if (selected.length === 0) throw new Error("Choose at least one file");
  if (selected.length > settings.maxFiles) {
    throw new Error(`Stored transfers can contain at most ${settings.maxFiles} files`);
  }
  const total = selected.reduce((sum, file) => sum + file.size, 0);
  if (!Number.isSafeInteger(total) || total > settings.maxTransferBytes) {
    throw new Error(`Stored transfer exceeds the ${settings.maxTransferBytes} byte limit`);
  }
  const names = new Set<string>();
  const prepared: StoredPreparedFile[] = [];
  let firstChunk = 0;
  for (let index = 0; index < selected.length; index += 1) {
    const file = selected[index];
    const name = normalizeOutgoingFileName(file.name);
    if (names.has(name)) throw new Error(`Duplicate filename: ${name}`);
    names.add(name);
    callbacks.onStatus?.(`Hashing ${index + 1}/${selected.length}: ${name}`);
    const chunkCount = Math.ceil(file.size / storedChunkSize);
    prepared.push({

View on GitHub (pinned to e25f1bdc04)

Solutions

  1. Disable the send button until files.length > 0 in the UI
  2. Guard at the call site: if (!files.length) return, before invoking prepareStoredFiles
  3. Show a file-chooser error message so the user re-selects files

Example fix

// before
const prepared = await prepareStoredFiles(selected, settings);

// after
if (selected.length === 0) { alert("Choose at least one file"); return; }
const prepared = await prepareStoredFiles(selected, settings);
Defensive patterns

Strategy: validation

Validate before calling

if (selected.length === 0) { showError("Choose at least one file"); return; }

Prevention

When it happens

Trigger: Calling prepareStoredFiles([]) — e.g., a file input that was cleared, drag-select that matched nothing, or a folder with no files passed through.

Common situations: UI bugs where the selection state resets before submit; programmatic pipelines that glob a directory and pass the empty result without checking.

Related errors


AI-assisted analysis of schollz/croc@e25f1bdc04 (2026-08-15). Data as JSON: /api/errors/0af14c53042fcaac. Report an issue: GitHub.