gastownhall/beads · error
check commit existence: %w
Error message
check commit existence: %w
What it means
CommitExists wraps a failed COUNT(*) query over dolt_log (exact hash or prefix via LIKE) as "check commit existence: <underlying>". The library throws it because the existence probe itself failed at the SQL level — it does not mean the commit is absent (that returns (false, nil)). Causes mirror the other dolt_log readers: non-Dolt database, missing dolt_log table, or connection/context failure.
Source
Thrown at internal/storage/versioncontrolops/version_control.go:90
}
// CommitExists checks whether a commit hash (or prefix) exists in dolt_log.
// Returns false for empty strings or malformed input.
func CommitExists(ctx context.Context, db DBConn, commitHash string) (bool, error) {
if commitHash == "" {
return false, nil
}
if err := issueops.ValidateRef(commitHash); err != nil {
return false, nil
}
var count int
err := db.QueryRowContext(ctx, `
SELECT COUNT(*) FROM dolt_log
WHERE commit_hash = ? OR commit_hash LIKE ?
`, commitHash, commitHash+"%").Scan(&count)
if err != nil {
return false, fmt.Errorf("check commit existence: %w", err)
}
return count > 0, nil
}
// Merge merges the named branch into the current branch. The author string
// should be formatted as "Name <email>". Returns any merge conflicts.
//
// This runs as a bare DOLT_MERGE under autocommit, so a real conflict makes
// Dolt reject the implicit transaction (Error 1105: "@autocommit must be
// disabled so that merge conflicts can be resolved ...") before dolt_conflicts
// can even be inspected — conflicts = error here, same as plain `dolt merge`
// with no further flags. Callers that want the flag Dolt's error names —
// resolve-then-commit on conflict — must use MergeWithStrategy instead, which
// runs the merge on a pinned session with the conflict-tolerant flags set
// (#4992).
func Merge(ctx context.Context, db DBConn, branch, author string) ([]storage.Conflict, error) {
_, err := db.ExecContext(ctx, "CALL DOLT_MERGE('--author', ?, ?)", author, branch)
if err != nil {View on GitHub (pinned to 71377f2769)
Solutions
- Verify the db is Dolt-initialized and has commits (SELECT 1 FROM dolt_log LIMIT 1).
- Check you are querying the database that actually contains the commit.
- Retry if the wrapped error is transient (connection reset, deadline exceeded).
- Treat non-transient unknown-table errors as 'database not initialized' and initialize it before checking hashes.
Example fix
// before ok, err := versioncontrolops.CommitExists(ctx, db, "abc123") // empty/uninitialized db // after // initialize the Dolt database (dolt init + first commit) first ok, err := versioncontrolops.CommitExists(ctx, db, "abc123")
Defensive patterns
Strategy: try-catch
Validate before calling
if commitHash == "" { return false, nil }
if err := issueops.ValidateRef(commitHash); err != nil { return false, nil }
var n int
if err := db.QueryRowContext(ctx, "SELECT 1 FROM dolt_log LIMIT 1").Scan(&n); err != nil {
return false, fmt.Errorf("no commit history in this database: %w", err)
} Try / catch
ok, err := versioncontrolops.CommitExists(ctx, db, hash)
if err != nil {
if strings.Contains(err.Error(), "check commit existence") {
// treat as 'cannot verify' rather than 'does not exist'
return fmt.Errorf("existence check unavailable: %w", err)
}
return err
} Prevention
- Never treat (false, err) as 'commit missing' — only (false, nil) means verified absence.
- Validate the hash with issueops.ValidateRef (the library does this internally and returns false for malformed input).
- Ensure the db you probe is the one the commit belongs to (hashes don't span databases).
- Call CommitExists after confirming dolt_log is queryable, or you will conflate 'uninitialized' with 'not found'.
When it happens
Trigger: Calling CommitExists on a db without dolt_log (never Dolt-initialized or zero commits); cancelled ctx; broken/stale connection.
Common situations: Validating a hash copied from another repo/directory that has no local dolt_log; running during embedded engine startup before the db is ready; wrong database pointed at.
Related errors
- table name cannot be empty
- check pending changes before commit: %w
- dolt add %s: %w
- check staged changes before commit: %w
- dolt commit: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/a945900fe220d42d.
Report an issue: GitHub.