{"record":{"id":"5f752bd51199be83","repo":"wavetermdev/waveterm","slug":"parent-block-not-found-q","errorCode":null,"errorMessage":"parent block not found: %q","messagePattern":"parent block not found: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wcore/block.go","lineNumber":45,"sourceCode":"\t}\n\tif blockDef.Meta == nil || blockDef.Meta.GetString(waveobj.MetaKey_View, \"\") == \"\" {\n\t\treturn nil, fmt.Errorf(\"no view provided for new block\")\n\t}\n\tblockData, err := createSubBlockObj(ctx, blockId, blockDef)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating sub block: %w\", err)\n\t}\n\tblockView := blockDef.Meta.GetString(waveobj.MetaKey_View, \"\")\n\tblockController := blockDef.Meta.GetString(waveobj.MetaKey_Controller, \"\")\n\tgo recordBlockCreationTelemetry(blockView, blockController, true)\n\treturn blockData, nil\n}\n\nfunc createSubBlockObj(ctx context.Context, parentBlockId string, blockDef *waveobj.BlockDef) (*waveobj.Block, error) {\n\treturn wstore.WithTxRtn(ctx, func(tx *wstore.TxWrap) (*waveobj.Block, error) {\n\t\tparentBlock, _ := wstore.DBGet[*waveobj.Block](tx.Context(), parentBlockId)\n\t\tif parentBlock == nil {\n\t\t\treturn nil, fmt.Errorf(\"parent block not found: %q\", parentBlockId)\n\t\t}\n\t\tblockId := uuid.NewString()\n\t\tblockData := &waveobj.Block{\n\t\t\tOID:         blockId,\n\t\t\tParentORef:  waveobj.MakeORef(waveobj.OType_Block, parentBlockId).String(),\n\t\t\tRuntimeOpts: nil,\n\t\t\tMeta:        blockDef.Meta,\n\t\t}\n\t\twstore.DBInsert(tx.Context(), blockData)\n\t\tparentBlock.SubBlockIds = append(parentBlock.SubBlockIds, blockId)\n\t\twstore.DBUpdate(tx.Context(), parentBlock)\n\t\treturn blockData, nil\n\t})\n}\n\nfunc CreateBlock(ctx context.Context, tabId string, blockDef *waveobj.BlockDef, rtOpts *waveobj.RuntimeOpts) (rtnBlock *waveobj.Block, rtnErr error) {\n\treturn CreateBlockWithTelemetry(ctx, tabId, blockDef, rtOpts, true)\n}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wcore/block.go#L27-L63","documentation":"Inside createSubBlockObj's transaction, the parent block is looked up by ID via wstore.DBGet; if no Block with that OID exists, creation aborts. A sub-block cannot be attached to a nonexistent parent.","triggerScenarios":"createSubBlockObj / CreateSubBlock called with a parentBlockId that does not exist in the Wave object store (already closed/deleted, or never existed).","commonSituations":"Client cached a stale block ID after the block was closed; race where the parent block was deleted between UI action and RPC; mistyped blockId in scripts.","solutions":["Fetch the current block list and use a live parent blockId","Re-query the block before creating a sub-block instead of reusing a cached ID","Handle the deletion case in UI code by refreshing block state before issuing the create"],"exampleFix":"// before\nblock, err := wcore.CreateSubBlock(ctx, staleBlockId, blockDef)\n// after\nparent, _ := wstore.DBGet[*waveobj.Block](ctx, parentBlockId)\nif parent != nil {\n    block, err := wcore.CreateSubBlock(ctx, parentBlockId, blockDef)\n}","handlingStrategy":"validation","validationCode":"parent, _ := wstore.DBGet[*waveobj.Block](ctx, parentBlockId)\nif parent == nil {\n    return fmt.Errorf(\"cannot create sub-block: parent %s no longer exists\", parentBlockId)\n}","typeGuard":null,"tryCatchPattern":"block, err := wcore.CreateSubBlock(ctx, parentBlockId, blockDef)\nif err != nil && strings.Contains(err.Error(), \"parent block not found\") {\n    // refresh block list / pick a valid parent\n}","preventionTips":["Re-fetch block IDs from the store instead of caching them","Handle block-closed events before issuing sub-block creation","Use current UI state (not stale layout data) for parent IDs"],"tags":["database","blocks","stale-reference"],"backgroundTag":"entity-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}