golang/go · error

missing origin

Error message

missing origin

What it means

vcsRepo.CheckReuse guards against a nil old origin at the top of the function. Callers must supply a previously-recorded Origin to compare against; passing nil means there is nothing to reuse.

Source

Thrown at src/cmd/go/internal/modfetch/codehost/vcs.go:382

	}
	return strings.TrimSpace(string(out)), nil
}

// repoSumOrigin returns an Origin containing a RepoSum.
func (r *vcsRepo) repoSumOrigin(ctx context.Context) *Origin {
	origin := &Origin{
		VCS:     r.cmd.vcs,
		URL:     r.remote,
		RepoSum: r.repoSum,
	}
	r.repoSumOnce.Do(func() { r.loadRepoSum(ctx) })
	origin.RepoSum = r.repoSum
	return origin
}

func (r *vcsRepo) CheckReuse(ctx context.Context, old *Origin, subdir string) error {
	if old == nil {
		return fmt.Errorf("missing origin")
	}
	if old.VCS != r.cmd.vcs || old.URL != r.remote {
		return fmt.Errorf("origin moved from %v %q to %v %q", old.VCS, old.URL, r.cmd.vcs, r.remote)
	}
	if old.Subdir != subdir {
		return fmt.Errorf("origin moved from %v %q %q to %v %q %q", old.VCS, old.URL, old.Subdir, r.cmd.vcs, r.remote, subdir)
	}

	if old.Ref == "" && old.RepoSum == "" && old.Hash != "" {
		// Hash has to remain in repo.
		hash, err := r.lookupRef(ctx, old.Hash)
		if err == nil && hash == old.Hash {
			return nil
		}
		if err != nil {
			return fmt.Errorf("looking up hash: %v", err)
		}
		return fmt.Errorf("hash changed") // weird but maybe they made a tag

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Run `go clean -modcache` to remove the orphaned module directory so the go command re-downloads with a fresh origin.
  2. Audit the caller to ensure a non-nil Origin is always supplied (this is an internal-API contract, not a user-facing knob).
  3. Verify the cache layout under GOMODCACHE/cache/download/<module>/@v/ — a missing .info or .origin file indicates an interrupted download.
Defensive patterns

Strategy: try-catch

Type guard

func hasOrigin(o *codehost.Origin) bool { return o != nil }

Try / catch

if err := repo.CheckReuse(ctx, old, subdir); err != nil {
    if strings.Contains(err.Error(), "missing origin") {
        // treat as cache miss, re-download instead of failing
        old = nil
    }
}

Prevention

When it happens

Trigger: CheckReuse invoked with old==nil — usually a caller bug where the cached origin was never persisted, was deserialised from a corrupt cache entry, or the caller is probing for reusability without a baseline.

Common situations: A corrupted module cache where the origin blob was deleted but the unpacked module remains; a codehost client wrapper that lazily passes nil when no prior download is recorded.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/58105823c6ca52a4. Report an issue: GitHub.