{"record":{"id":"a6caf4926093c8bf","repo":"gastownhall/beads","slug":"checking-issue-count-w","errorCode":null,"errorMessage":"checking issue count: %w","messagePattern":"checking issue count: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/embeddeddolt/store.go","lineNumber":741,"sourceCode":"}\n\n// ImportJSONLData atomically checks if the database is empty and, if so,\n// imports parsed issues and config key/value pairs in a single transaction.\n// Returns the count of issues imported, or 0 if the database was not empty.\n// Does NOT issue DOLT_COMMIT — the caller is responsible for committing\n// (e.g. via the PersistentPostRun auto-commit hook).\nfunc (s *EmbeddedDoltStore) ImportJSONLData(\n\tctx context.Context,\n\tissues []*types.Issue,\n\tconfigEntries map[string]string,\n\tactor string,\n) (int, error) {\n\tvar imported int\n\terr := s.withConn(ctx, true, func(tx *sql.Tx) error {\n\t\t// Atomically check: is the database empty?\n\t\tstats := &types.Statistics{}\n\t\tif err := issueops.ScanIssueCountsInTx(ctx, tx, stats); err != nil {\n\t\t\treturn fmt.Errorf(\"checking issue count: %w\", err)\n\t\t}\n\t\tif stats.TotalIssues > 0 {\n\t\t\treturn nil // database is not empty — skip import\n\t\t}\n\n\t\t// Import config entries (memories, etc.)\n\t\tfor key, value := range configEntries {\n\t\t\tif err := issueops.SetConfigInTx(ctx, tx, key, value); err != nil {\n\t\t\t\treturn fmt.Errorf(\"importing config %q: %w\", key, err)\n\t\t\t}\n\t\t}\n\n\t\tif len(issues) == 0 {\n\t\t\treturn nil\n\t\t}\n\n\t\t// Auto-detect prefix from first issue if not already provided\n\t\tif _, hasPrefix := configEntries[\"issue_prefix\"]; !hasPrefix {","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/embeddeddolt/store.go#L723-L759","documentation":"Wraps the error from ScanIssueCountsInTx during the import path (ensureConfig/import step) when the store checks inside a transaction whether the database is empty (total issues == 0) before importing config entries and issues. The count query failed — SQL error, transaction/connection problem, or context cancellation — so the store cannot safely decide whether to import and aborts the operation.","triggerScenarios":"Calling the import path (e.g. ImportIssues/BatchCreate with configEntries) on an EmbeddedDoltStore where: (1) the SELECT counting issues fails (schema missing/mismatched — e.g. migrations not applied); (2) the write transaction's connection breaks; (3) ctx is cancelled mid-query.","commonSituations":"Opening a database whose schema wasn't fully migrated, then attempting an import; engine hiccup or killed process mid-transaction; cancelled context in a long import script.","solutions":["Run 'bd migrate' / open once normally so the schema is up to date, then retry the import.","Check the wrapped inner error for the exact SQL failure and address it (missing table → migrate; lock → retry).","Retry the import — the empty-check plus transaction design makes it safe to re-run.","Ensure the context stays alive for the duration of the import."],"exampleFix":"// before\nstore.ImportIssues(ctx, issues, cfgEntries) // ctx cancelled mid-import\n\n// after\nimportCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()\nstore.ImportIssues(importCtx, issues, cfgEntries)","handlingStrategy":"retry","validationCode":"if err := ctx.Err(); err != nil { return err }\n// ensure schema is current before importing\nif out, err := exec.Command(\"bd\", \"migrate\").CombinedOutput(); err != nil {\n    return fmt.Errorf(\"migrate before import: %v: %s\", err, out)\n}","typeGuard":null,"tryCatchPattern":"err := store.ImportIssues(ctx, issues, cfg)\nif err != nil && strings.Contains(err.Error(), \"checking issue count\") {\n    // safe to retry: transactional, DB left untouched\n    return store.ImportIssues(ctx, issues, cfg)\n}","preventionTips":["Apply schema migrations before any import","Keep the context alive for the whole import; use a dedicated timeout","Retry imports freely — the empty-check makes them idempotent","Watch for engine/connection errors in logs during large imports"],"tags":["embedded-dolt","sql","import","transaction"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}