{"record":{"id":"c6ba89db3ae6c67b","repo":"gastownhall/beads","slug":"failed-to-get-diff-w","errorCode":null,"errorMessage":"failed to get diff: %w","messagePattern":"failed to get diff: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/diff.go","lineNumber":38,"sourceCode":"\tif err := ValidateRef(toRef); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid toRef: %w\", err)\n\t}\n\n\tquery := fmt.Sprintf(`\n\t\tSELECT\n\t\t\tCOALESCE(from_id, '') as from_id,\n\t\t\tCOALESCE(to_id, '') as to_id,\n\t\t\tdiff_type,\n\t\t\tfrom_title, to_title,\n\t\t\tfrom_description, to_description,\n\t\t\tfrom_status, to_status,\n\t\t\tfrom_priority, to_priority\n\t\tFROM dolt_diff('%s', '%s', 'issues')\n\t`, fromRef, toRef)\n\n\trows, err := tx.QueryContext(ctx, query)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get diff: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tvar entries []*storage.DiffEntry\n\tfor rows.Next() {\n\t\tvar fromID, toID, diffType string\n\t\tvar fromTitle, toTitle, fromDesc, toDesc, fromStatus, toStatus *string\n\t\tvar fromPriority, toPriority *int\n\n\t\tif err := rows.Scan(&fromID, &toID, &diffType,\n\t\t\t&fromTitle, &toTitle,\n\t\t\t&fromDesc, &toDesc,\n\t\t\t&fromStatus, &toStatus,\n\t\t\t&fromPriority, &toPriority); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to scan diff: %w\", err)\n\t\t}\n\n\t\tentry := &storage.DiffEntry{","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/diff.go#L20-L56","documentation":"This error wraps a failure executing the dolt_diff() table-function query in DiffInTx. Refs were already validated, so failures come from the database: an unknown ref (branch/commit doesn't exist), a missing issues table, a Dolt engine error, or a connection problem. It means the diff could not start streaming rows at all.","triggerScenarios":"tx.QueryContext on \"SELECT ... FROM dolt_diff('<from>','<to>','issues')\" fails: non-existent fromRef/toRef in the local database, issues table absent at those refs, Dolt engine error, or connection failure.","commonSituations":"Diffing a branch that was never fetched (exists only on the remote); diffing against a bare/non-Dolt database where dolt_diff() doesn't exist; diffing before the issues table was created at the given ref.","solutions":["Check the wrapped cause: an 'unknown ref' error means the branch/commit is absent locally — fetch or create it first","Verify both refs resolve (e.g. dolt branch / query dolt_log) before diffing","Confirm the issues table exists at both refs","Ensure you are connected to a Dolt database; dolt_diff is Dolt-specific and unavailable on MySQL/SQLite"],"exampleFix":"// before\nrows, err := tx.QueryContext(ctx, query)\nif err != nil {\n    return nil, fmt.Errorf(\"failed to get diff: %w\", err)\n}\n// after\nrows, err := tx.QueryContext(ctx, query)\nif err != nil {\n    return nil, fmt.Errorf(\"failed to get diff %s..%s (does the ref exist locally? run fetch first): %w\", fromRef, toRef, err)\n}","handlingStrategy":"try-catch","validationCode":"// verify refs and table exist before diffing\nfor _, ref := range []string{from, to} {\n    if err := db.QueryRow(\"SELECT COUNT(*) FROM dolt_branches WHERE name = ?\", ref).Scan(&n); err != nil || n == 0 {\n        if !isCommitRef(ref) { // fall back: try resolving as commit hash\n            return fmt.Errorf(\"ref %q not found locally; run fetch first\", ref)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"entries, err := issueops.DiffInTx(ctx, tx, from, to)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to get diff\") && strings.Contains(err.Error(), \"unknown ref\") {\n        // fetch or create the missing ref, then retry once\n        return retryAfterFetch(ctx, from, to)\n    }\n    return err\n}","preventionTips":["Run dolt fetch (or the equivalent) before diffing remote branches","Confirm you are connected to a Dolt database — dolt_diff() is Dolt-only","Ensure the issues table exists at both refs","Surface the wrapped driver error to users instead of hiding it"],"tags":["database","dolt","sql","diff"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}