wavetermdev/waveterm · error

error creating sub block: %w

Error message

error creating sub block: %w

What it means

This wraps any failure from the internal createSubBlockObj, which runs in a DB transaction (wstore.WithTxRtn) to create the block object and attach it to the parent block. It is a wrapper error; the real cause is the %w-wrapped inner error.

Source

Thrown at pkg/wcore/block.go:33

	"github.com/wavetermdev/waveterm/pkg/telemetry"
	"github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata"
	"github.com/wavetermdev/waveterm/pkg/util/utilfn"
	"github.com/wavetermdev/waveterm/pkg/waveobj"
	"github.com/wavetermdev/waveterm/pkg/wps"
	"github.com/wavetermdev/waveterm/pkg/wshrpc"
	"github.com/wavetermdev/waveterm/pkg/wstore"
)

func CreateSubBlock(ctx context.Context, blockId string, blockDef *waveobj.BlockDef) (*waveobj.Block, error) {
	if blockDef == nil {
		return nil, fmt.Errorf("blockDef is nil")
	}
	if blockDef.Meta == nil || blockDef.Meta.GetString(waveobj.MetaKey_View, "") == "" {
		return nil, fmt.Errorf("no view provided for new block")
	}
	blockData, err := createSubBlockObj(ctx, blockId, blockDef)
	if err != nil {
		return nil, fmt.Errorf("error creating sub block: %w", err)
	}
	blockView := blockDef.Meta.GetString(waveobj.MetaKey_View, "")
	blockController := blockDef.Meta.GetString(waveobj.MetaKey_Controller, "")
	go recordBlockCreationTelemetry(blockView, blockController, true)
	return blockData, nil
}

func createSubBlockObj(ctx context.Context, parentBlockId string, blockDef *waveobj.BlockDef) (*waveobj.Block, error) {
	return wstore.WithTxRtn(ctx, func(tx *wstore.TxWrap) (*waveobj.Block, error) {
		parentBlock, _ := wstore.DBGet[*waveobj.Block](tx.Context(), parentBlockId)
		if parentBlock == nil {
			return nil, fmt.Errorf("parent block not found: %q", parentBlockId)
		}
		blockId := uuid.NewString()
		blockData := &waveobj.Block{
			OID:         blockId,
			ParentORef:  waveobj.MakeORef(waveobj.OType_Block, parentBlockId).String(),
			RuntimeOpts: nil,

View on GitHub (pinned to a4447c1563)

Solutions

  1. Inspect the wrapped inner error to identify the root cause
  2. Verify the parent blockId exists and has not been deleted
  3. Retry after resolving DB issues (lock contention, disk space)
Defensive patterns

Strategy: try-catch

Validate before calling

parent, _ := wstore.DBGet[*waveobj.Block](ctx, parentBlockId)
if parent == nil { return errors.New("parent missing, aborting") }

Try / catch

block, err := wcore.CreateSubBlock(ctx, blockId, blockDef)
if err != nil {
    var wrapped string = err.Error() // contains inner cause via %w
    if errors.Is(err, someDBErr) { /* retry/backoff */ }
}

Prevention

When it happens

Trigger: CreateSubBlock called with a valid blockDef but createSubBlockObj fails: parent block missing, database/transaction error, or constraint failure while persisting the new block.

Common situations: Referencing a stale or deleted parent blockId; SQLite store locked or corrupted; concurrent modification of the parent block.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/8fb04dc34c629de1. Report an issue: GitHub.