{"record":{"id":"29b852b0d0b78e44","repo":"gastownhall/beads","slug":"batch-create-molecules-w","errorCode":null,"errorMessage":"batch create molecules: %w","messagePattern":"batch create molecules: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/molecules/molecules.go","lineNumber":155,"sourceCode":"\t\t\t// Already exists - skip (or could update if newer)\n\t\t\tdebug.Logf(\"molecule %s already exists, skipping\", mol.ID)\n\t\t\tcontinue\n\t\t}\n\n\t\tnewMolecules = append(newMolecules, mol)\n\t}\n\n\tif len(newMolecules) == 0 {\n\t\treturn 0, nil\n\t}\n\n\t// Use batch creation with prefix validation skipped.\n\t// Molecules have their own ID namespace (mol-*) independent of project prefix.\n\topts := storage.BatchCreateOptions{\n\t\tSkipPrefixValidation: true, // Molecules use their own prefix\n\t}\n\tif err := l.store.CreateIssuesWithFullOptions(ctx, newMolecules, \"molecules-loader\", opts); err != nil {\n\t\treturn 0, fmt.Errorf(\"batch create molecules: %w\", err)\n\t}\n\treturn len(newMolecules), nil\n}\n\n// loadMoleculesFromFile loads molecules from a JSONL file.\nfunc loadMoleculesFromFile(path string) ([]*types.Issue, error) {\n\t// Check if file exists\n\tif _, err := os.Stat(path); os.IsNotExist(err) {\n\t\treturn nil, nil\n\t}\n\n\t// #nosec G304 - path is constructed from known safe locations\n\tfile, err := os.Open(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open %s: %w\", path, err)\n\t}\n\tdefer file.Close()\n","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/molecules/molecules.go#L137-L173","documentation":"LoadAll batch-creates all validated molecules through storage in one call. If CreateIssuesWithFullOptions fails for any of the new mol-* issues, the storage error is wrapped with this message and loading aborts, returning 0 loaded.","triggerScenarios":"Any storage-layer failure inside CreateIssuesWithFullOptions during LoadAll's molecule load: DB closed/corrupt, constraint violation (duplicate mol- ID), or transaction failure. Prefix validation is skipped because molecules use their own mol- prefix.","commonSituations":"Duplicate molecule IDs across multiple molecules.jsonl files; Dolt/DB connection dropped mid-load; loading into an uninitialized or read-only store.","solutions":["Read the wrapped inner error (%w) to identify the storage cause; fix that first (e.g. remove the duplicate mol- ID from the JSONL).","Verify the store is initialized, writable, and reachable before running LoadAll.","Re-run LoadAll after correcting the input files or storage."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"n, err := LoadAll(ctx, store, dir)\nif err != nil {\n    var storageErr *storage.Error\n    if errors.As(err, &storageErr) {\n        return fmt.Errorf(\"molecule insert failed: %w\", storageErr)\n    }\n    return err\n}","preventionTips":["Ensure molecule IDs are unique across all loaded JSONL files","Verify store connectivity before batch loads","Load into a scratch store first when testing new molecule sets"],"tags":["storage","batch-insert","molecules"],"backgroundTag":"batch-create-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}