{"record":{"id":"507605d2b9fb2e7e","repo":"gastownhall/beads","slug":"get-log-w","errorCode":null,"errorMessage":"get log: %w","messagePattern":"get log: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/version_control.go","lineNumber":59,"sourceCode":"\t\t}\n\t}\n\treturn status, rows.Err()\n}\n\n// Log returns recent commit history up to limit entries.\n// If limit is 0 or negative, all entries are returned.\nfunc Log(ctx context.Context, db DBConn, limit int) ([]storage.CommitInfo, error) {\n\tvar query string\n\tvar args []interface{}\n\tif limit > 0 {\n\t\tquery = \"SELECT commit_hash, committer, email, date, message FROM dolt_log ORDER BY date DESC LIMIT ?\"\n\t\targs = []interface{}{limit}\n\t} else {\n\t\tquery = \"SELECT commit_hash, committer, email, date, message FROM dolt_log ORDER BY date DESC\"\n\t}\n\trows, err := db.QueryContext(ctx, query, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get log: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tvar commits []storage.CommitInfo\n\tfor rows.Next() {\n\t\tvar c storage.CommitInfo\n\t\tif err := rows.Scan(&c.Hash, &c.Author, &c.Email, &c.Date, &c.Message); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scan commit: %w\", err)\n\t\t}\n\t\tcommits = append(commits, c)\n\t}\n\treturn commits, rows.Err()\n}\n\n// CommitExists checks whether a commit hash (or prefix) exists in dolt_log.\n// Returns false for empty strings or malformed input.\nfunc CommitExists(ctx context.Context, db DBConn, commitHash string) (bool, error) {\n\tif commitHash == \"\" {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/version_control.go#L41-L77","documentation":"Log wraps a failed query against dolt_log (with or without LIMIT ?) as \"get log: <underlying>\". The library throws it because the commit-history query failed before rows were returned. dolt_log only exists in a Dolt database with at least one commit, so the most common causes are a non-Dolt/uninitialized database or a connection/context failure.","triggerScenarios":"Calling Log on a database with no commits (fresh, uninitialized dolt dir) so dolt_log is missing or empty-erroring; querying a non-Dolt schema; ctx cancelled or connection reset mid-query.","commonSituations":"Running bd vc log right after creating a database that has never had a Dolt commit; pointing at the wrong database/directory; embedded engine restart dropping the connection.","solutions":["Confirm the database has commit history: SELECT COUNT(*) FROM dolt_log — if the table is missing, the db was never Dolt-initialized; run dolt init / make an initial commit.","Verify you are pointed at the intended database directory/schema.","Reconnect (recycle the stale connection) and retry; check ctx deadlines.","Inspect the wrapped error for unknown-table vs. connection errors and address the specific cause."],"exampleFix":"// before\ncommits, err := versioncontrolops.Log(ctx, db, 10) // fresh db, no dolt_log\n// after\n// make the first commit so dolt_log exists:\n// dolt add -A && dolt commit -m \"init\"\ncommits, err := versioncontrolops.Log(ctx, db, 10)","handlingStrategy":"validation","validationCode":"// ensure the db has commit history before requesting the log\nvar n int\nif err := db.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_log\").Scan(&n); err != nil {\n    return fmt.Errorf(\"no dolt_log (initialize the Dolt database first): %w\", err)\n}\n_ = n","typeGuard":"func hasCommitHistory(ctx context.Context, db DBConn) bool {\n    var n int\n    return db.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_log\").Scan(&n) == nil\n}","tryCatchPattern":"commits, err := versioncontrolops.Log(ctx, db, limit)\nif err != nil {\n    if strings.Contains(err.Error(), \"get log\") && strings.Contains(err.Error(), \"dolt_log\") {\n        return nil, fmt.Errorf(\"database has no commit history; run dolt init + first commit\")\n    }\n    return nil, err\n}","preventionTips":["Verify the database was Dolt-initialized and has at least one commit before reading history.","Confirm the connection string/directory points at the intended database.","Wrap log reads with a ctx timeout so hangs surface as errors quickly.","After an engine restart, recycle stale connections before querying."],"tags":["dolt","sql","log","history"],"backgroundTag":"unknown-sql-table","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}