wavetermdev/waveterm · error
bad block parent oref: %v
Error message
bad block parent oref: %v
What it means
While walking a block's parent chain, DBFindTabForBlockId parses each parentoref string into an ORef. If the stored parentoref is empty, malformed, or not a valid 'type:id' reference, ParseORef fails and the error is wrapped with this message.
Source
Thrown at pkg/wstore/wstore_dbops.go:378
return nil
})
}
func DBFindTabForBlockId(ctx context.Context, blockId string) (string, error) {
return WithTxRtn(ctx, func(tx *TxWrap) (string, error) {
iterNum := 1
for {
if iterNum > 5 {
return "", fmt.Errorf("too many iterations looking for tab in block parents")
}
query := `
SELECT json_extract(b.data, '$.parentoref') AS parentoref
FROM db_block b
WHERE b.oid = ?;`
parentORef := tx.GetString(query, blockId)
oref, err := waveobj.ParseORef(parentORef)
if err != nil {
return "", fmt.Errorf("bad block parent oref: %v", err)
}
if oref.OType == "tab" {
return oref.OID, nil
}
if oref.OType == "block" {
blockId = oref.OID
iterNum++
continue
}
return "", fmt.Errorf("bad parent oref type: %v", oref.OType)
}
})
}
func DBFindWorkspaceForTabId(ctx context.Context, tabId string) (string, error) {
return WithTxRtn(ctx, func(tx *TxWrap) (string, error) {
query := `
WITH variable(value) AS (View on GitHub (pinned to a4447c1563)
Solutions
- Fix or delete the corrupt db_block row so parentoref is a valid 'tab:...' or 'block:...' ORef
- Re-establish the parent relationship by moving the block into a tab via the layout API
- Guard callers: check block has a parent before resolving, and log the raw parentoref value for diagnosis
Defensive patterns
Strategy: try-catch
Validate before calling
raw := getBlockParentORef(blockId) // your own read
if _, err := waveobj.ParseORef(raw); err != nil { /* repair before traversal */ } Try / catch
tabId, err := wstore.DBFindTabForBlockId(ctx, blockId)
if err != nil && strings.Contains(err.Error(), "bad block parent oref") {
// repair or re-parent the block, then retry
} Prevention
- Only set parentoref via the layout APIs, never raw strings
- Validate ORefs with ParseORef before persisting
- Backup/migrate DB rows when upgrading versions
When it happens
Trigger: A db_block row whose JSON $.parentoref is empty string, truncated, or contains an invalid reference format passed to waveobj.ParseORef during DBFindTabForBlockId.
Common situations: Database rows written by older/buggy versions with missing parent fields; manual DB edits; objects copied between databases losing their parent linkage.
Related errors
- bad parent oref type: %v
- badge oref must be a block or tab (got %q)
- too many flush errors (clearing entry): %w
- opening db: %w
- failed to create job in database: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/da31acaaa10b85ec.
Report an issue: GitHub.