{"record":{"id":"27a337d532d37b56","repo":"gastownhall/beads","slug":"get-next-child-id-scan-child-row-w","errorCode":null,"errorMessage":"get next child ID: scan child row: %w","messagePattern":"get next child ID: scan child row: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/child_id.go","lineNumber":40,"sourceCode":"\t} else if err != nil {\n\t\treturn \"\", fmt.Errorf(\"get next child ID: read counter: %w\", err)\n\t}\n\n\t//nolint:gosec // G201: issueTable is one of two hardcoded constants.\n\trows, err := tx.QueryContext(ctx, fmt.Sprintf(`\n\t\tSELECT id FROM %s\n\t\tWHERE id LIKE CONCAT(?, '.%%')\n\t\t  AND id NOT LIKE CONCAT(?, '.%%.%%')\n\t`, issueTable), parentID, parentID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"get next child ID: query existing children: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tfor rows.Next() {\n\t\tvar id string\n\t\tif err := rows.Scan(&id); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get next child ID: scan child row: %w\", err)\n\t\t}\n\t\t_, childNum, ok := ParseHierarchicalID(id)\n\t\tif ok && childNum > lastChild {\n\t\t\tlastChild = childNum\n\t\t}\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"get next child ID: iterate children: %w\", err)\n\t}\n\n\tnextChild := lastChild + 1\n\n\t//nolint:gosec // G201: counterTable is one of two hardcoded constants.\n\tif _, err := tx.ExecContext(ctx, fmt.Sprintf(`\n\t\tINSERT INTO %s (parent_id, last_child) VALUES (?, ?)\n\t\tON DUPLICATE KEY UPDATE last_child = ?\n\t`, counterTable), parentID, nextChild, nextChild); err != nil {\n\t\treturn \"\", fmt.Errorf(\"get next child ID: update counter: %w\", err)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/child_id.go#L22-L58","documentation":"While iterating child-ID rows, rows.Scan(&id) into a string failed and is wrapped as \"get next child ID: scan child row: %w\". Since the query selects only the id column (a string), this indicates a driver-level row conversion or connection problem rather than bad data shape.","triggerScenarios":"Iterating results of the child-ID LIKE query when: a row's id value cannot be converted to string (corrupt or NULL row), or the underlying connection drops mid-iteration so the driver cannot fetch the next row.","commonSituations":"Corrupted database files after a crash; NULL or binary data in the id column from manual edits; network interruption during a large result-set scan against a remote Dolt server.","solutions":["Inspect and repair the issues table rows for the affected parent (check for NULL/corrupt id values).","Retry the operation; mid-iteration connection drops are usually transient.","If corruption is suspected, restore from git-tracked issues.jsonl export and re-import.","Check wrapped error text: 'converting NULL to string' points at bad rows; 'connection refused/bad connection' points at the server."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    tx.Rollback()\n    if strings.Contains(err.Error(), \"connection\") { return retry(err) }\n    return fmt.Errorf(\"corrupt child row: %w\", err)\n}","preventionTips":["Never manually edit the issues table or export/import with mismatched schemas.","Restore from .beads/issues.jsonl if corruption is detected.","Use stable connections (embedded/local mode) for very large parents.","Back up the database before risky operations."],"tags":["database","sql","scan","corruption"],"backgroundTag":"sql-scan-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}