wavetermdev/waveterm · error

error getting client: %w

Error message

error getting client: %w

What it means

After inserting the window, CreateWindow reads the singleton Client record via GetClientData to append the new windowId; this error wraps a failure reading that client record. The window row already exists at this point, so a failure here leaves a partially-created window.

Source

Thrown at pkg/wcore/window.go:120

		}
	}
	window := &waveobj.Window{
		OID:         windowId,
		WorkspaceId: ws.OID,
		IsNew:       true,
		Pos: waveobj.Point{
			X: 0,
			Y: 0,
		},
		WinSize: *winSize,
	}
	err := wstore.DBInsert(ctx, window)
	if err != nil {
		return nil, fmt.Errorf("error inserting window: %w", err)
	}
	client, err := GetClientData(ctx)
	if err != nil {
		return nil, fmt.Errorf("error getting client: %w", err)
	}
	client.WindowIds = append(client.WindowIds, windowId)
	err = wstore.DBUpdate(ctx, client)
	if err != nil {
		return nil, fmt.Errorf("error updating client: %w", err)
	}
	return GetWindow(ctx, windowId)
}

// CloseWindow closes a window and deletes its workspace if it is empty and not named.
// If fromElectron is true, it does not send an event to Electron.
func CloseWindow(ctx context.Context, windowId string, fromElectron bool) error {
	log.Printf("CloseWindow %s\n", windowId)
	window, err := GetWindow(ctx, windowId)
	if err == nil {
		log.Printf("got window %s\n", windowId)
		deleted, _, err := DeleteWorkspace(ctx, window.WorkspaceId, false)
		if err != nil {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Ensure wcore.EnsureInitialData has run before creating windows
  2. Check the wrapped %w error — 'not found' means the client singleton is missing
  3. Re-initialize the client data or restore the DB
  4. Clean up the already-inserted window row if aborting

Example fix

// before
client, err := GetClientData(ctx)
if err != nil {
	return nil, fmt.Errorf("error getting client: %w", err)
}
// after
client, err := GetClientData(ctx)
if err != nil {
	_ = wstore.DBDelete(ctx, waveobj.OType_Window, windowId) // roll back partial creation
	return nil, fmt.Errorf("error getting client (is client data initialized?): %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := wcore.GetClientData(ctx); err != nil {
	if err := wcore.EnsureInitialData(); err != nil {
		return fmt.Errorf("client data unavailable: %w", err)
	}
}

Try / catch

win, err := wcore.CreateWindow(ctx, winSize, workspaceId)
if err != nil && strings.Contains(err.Error(), "error getting client") {
	// window row may exist but be unregistered; run CheckAndFixWindow or re-init
	if initErr := wcore.EnsureInitialData(); initErr != nil {
		return initErr
	}
	return err
}

Prevention

When it happens

Trigger: wcore.CreateWindow when GetClientData(ctx) fails — the client singleton is missing from the DB (fresh/uninitialized DB where EnsureInitialData never ran) or the singleton read errors.

Common situations: Calling CreateWindow before EnsureInitialData on a brand-new install; DB reset/corruption removing the client singleton; read error on the state DB.

Related errors


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