sinelaw/fresh · warning

[pkg] Failed to clone registry

Error message

[pkg] Failed to clone registry ${source}: ${result.stderr}

What it means

`editor.warn` from `syncRegistry` in pkg.ts:523, emitted when cloning a new registry fails: `[pkg] Failed to clone registry ${source}: ${result.stderr}`. The plugin surfaces raw git clone stderr; packages from that registry are unavailable until the clone succeeds.

Solutions

  1. Correct the registry source URL in the pkg configuration
  2. Ensure credentials are available (HTTPS token or SSH key) for private registries
  3. Remove any partial/existing directory at `indexPath` and re-run sync
  4. Check network connectivity / proxy; the warn text maps 'Could not resolve host' to Network error

Example fix

// before
editor.warn(`[pkg] Failed to clone registry ${source}: ${result.stderr}`);
// after
if (result.stderr.includes("not found") || result.exit_code === 128) {
  editor.warn(`[pkg] Registry not found, check URL: ${source}`);
}
Defensive patterns

Strategy: retry

Validate before calling

// validate before cloning
if (!/^([\w.-]+@)?[\w.-]+[:/][\w./-]+$/.test(source)) { editor.warn(`[pkg] Bad registry URL: ${source}`); return; }
// ensure target path is clean
if (fsLocal.exists(indexPath)) fsLocal.removePath(indexPath);

Type guard

function isCloneableUrl(source) { return /^https:\/\/.+/.test(source) || /^git@.+/.test(source); }

Try / catch

const result = await gitCommand(['clone','--depth','1',source,indexPath]);
if (result.exit_code !== 0) {
  if (result.stderr.includes('not found') || result.stderr.includes('404')) { editor.warn(`[pkg] Registry not found: ${source}`); return; }
  if (attempt < 2) return cloneWithRetry(source, attempt + 1);
  editor.warn(`[pkg] Failed to clone registry ${source}: ${result.stderr}`);
}

Prevention

When it happens

Trigger: First-time `git clone --depth 1 <source> <indexPath>` exits non-zero: host not resolvable, 404 / repo not found, auth required (private repo, 403), or local clone path issues.

Common situations: Typo'd or removed registry URL; private registry without credentials; offline/blocked network; index directory not writable or pre-existing partial clone blocking the clone.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/196cf9bd3b95d654. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor/plugins/pkg.ts:523

        errors.push(`${source}: ${errorMsg}`);
        editor.warn(`[pkg] Failed to update registry ${source}: ${result.stderr}`);
      }
    } else {
      // Clone new
      editor.setStatus(`Cloning registry: ${source}...`);
      const result = await gitCommand(["clone", "--depth", "1", `${source}`, `${indexPath}`]);
      if (result.exit_code === 0) {
        synced++;
      } else {
        const errorMsg = result.stderr.includes("Could not resolve host")
          ? "Network error"
          : result.stderr.includes("not found") || result.stderr.includes("404")
          ? "Repository not found"
          : result.stderr.includes("Authentication") || result.stderr.includes("403")
          ? "Authentication failed (check if repo is public)"
          : result.stderr.split("\n")[0] || "Unknown error";
        errors.push(`${source}: ${errorMsg}`);
        editor.warn(`[pkg] Failed to clone registry ${source}: ${result.stderr}`);
      }
    }
  }

  // Cache registry data locally for faster startup next time
  if (synced > 0) {
    await cacheRegistry();
  }

  if (errors.length > 0) {
    editor.setStatus(`Registry: ${synced}/${sources.length} synced. Errors: ${errors.join("; ")}`);
  } else {
    editor.setStatus(`Registry synced (${synced}/${sources.length} sources)`);
  }
}

/**
 * Load merged registry data from git index or cache

View on GitHub (pinned to 67894ca546)