wavetermdev/waveterm · error

error deleting block: %w

Error message

error deleting block: %w

What it means

DeleteBlock wraps failures from wcore.DeleteBlock(ctx, blockId, true) with 'error deleting block: %w'. The block removal failed in the core layer — typically the blockId does not exist, or cascading cleanup of the block's children/refs failed.

Source

Thrown at pkg/service/objectservice/objectservice.go:110

		return "", nil, err
	}

	return blockData.OID, waveobj.ContextGetUpdatesRtn(ctx), nil
}

func (svc *ObjectService) DeleteBlock_Meta() tsgenmeta.MethodMeta {
	return tsgenmeta.MethodMeta{
		ArgNames: []string{"uiContext", "blockId"},
	}
}

func (svc *ObjectService) DeleteBlock(uiContext waveobj.UIContext, blockId string) (waveobj.UpdatesRtnType, error) {
	ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
	defer cancelFn()
	ctx = waveobj.ContextWithUpdates(ctx)
	err := wcore.DeleteBlock(ctx, blockId, true)
	if err != nil {
		return nil, fmt.Errorf("error deleting block: %w", err)
	}
	return waveobj.ContextGetUpdatesRtn(ctx), nil
}

func (svc *ObjectService) UpdateObjectMeta_Meta() tsgenmeta.MethodMeta {
	return tsgenmeta.MethodMeta{
		ArgNames: []string{"uiContext", "oref", "meta"},
	}
}

func (svc *ObjectService) UpdateObjectMeta(uiContext waveobj.UIContext, orefStr string, meta waveobj.MetaMapType) (waveobj.UpdatesRtnType, error) {
	ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
	defer cancelFn()
	ctx = waveobj.ContextWithUpdates(ctx)
	oref, err := parseORef(orefStr)
	if err != nil {
		return nil, fmt.Errorf("error parsing object reference: %w", err)
	}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Check the wrapped error: 'key not found' means the block is already gone — treat the delete as idempotent success
  2. Refresh the block list before retrying the delete
  3. Verify the id is a block id (OType 'block'), not another object type

Example fix

// before
_, err := svc.DeleteBlock(uiContext, blockId)
// after
if _, err := svc.DeleteBlock(uiContext, blockId); err != nil && strings.Contains(err.Error(), "key not found") {
    // already deleted; continue
    return nil
}
Defensive patterns

Strategy: try-catch

Validate before calling

if blockId == "" { return fmt.Errorf("blockId required") }

Try / catch

_, err := svc.DeleteBlock(uiContext, blockId)
if err != nil {
    if strings.Contains(err.Error(), "key not found") { return nil } // already gone
    return err
}

Prevention

When it happens

Trigger: Calling ObjectService.DeleteBlock with an already-deleted or never-existing blockId, or when the underlying tab/layout update fails during cascade delete.

Common situations: Double-invoking a close action on the same block; deleting from a stale UI list after another window closed the block; id mix-ups (passing tabId as blockId).

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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