{"record":{"id":"4c7adee1930522d2","repo":"wavetermdev/waveterm","slug":"no-active-window","errorCode":null,"errorMessage":"no active window","messagePattern":"no active window","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshrpc/wshserver/wshserver.go","lineNumber":904,"sourceCode":"\n\t// Resolve the set of workspaces to inspect\n\tvar workspaceIDs []string\n\tif req.WorkspaceId != \"\" {\n\t\tworkspaceIDs = []string{req.WorkspaceId}\n\t} else if req.WindowId != \"\" {\n\t\twin, err := wcore.GetWindow(ctx, req.WindowId)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tworkspaceIDs = []string{win.WorkspaceId}\n\t} else {\n\t\t// \"current\" == first workspace in client focus list\n\t\tclient, err := wstore.DBGetSingleton[*waveobj.Client](ctx)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif len(client.WindowIds) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"no active window\")\n\t\t}\n\t\twin, err := wcore.GetWindow(ctx, client.WindowIds[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tworkspaceIDs = []string{win.WorkspaceId}\n\t}\n\n\tfor _, wsID := range workspaceIDs {\n\t\twsData, err := wcore.GetWorkspace(ctx, wsID)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\twindowId, err := wstore.DBFindWindowForWorkspaceId(ctx, wsID)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"error finding window for workspace %s: %v\", wsID, err)\n\t\t}","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshrpc/wshserver/wshserver.go#L886-L922","documentation":"BlocksListCommand with WindowId \"current\" resolves the current window via the client singleton's WindowIds focus list. If the client record has no windows (empty WindowIds), it cannot resolve a window and returns 'no active window'.","triggerScenarios":"Calling BlocksListCommand with WindowId=\"current\" when the client's WindowIds list is empty — no window has been created or all windows were closed.","commonSituations":"Running wsh block commands headlessly or in tests before any window exists; server-side automation with no UI; client state not yet initialized.","solutions":["Create/open a window first so client.WindowIds is populated","Pass an explicit WindowId or WorkspaceId instead of \"current\"","Check for leaked/wrong client state in tests (seed a client with a window in fixtures)"],"exampleFix":"// before\nblocks, err := client.BlocksListCommand(ctx, wshrpc.CommandBlocksListData{WindowId: \"current\"})\n// after\nblocks, err := client.BlocksListCommand(ctx, wshrpc.CommandBlocksListData{WorkspaceId: workspaceId})","handlingStrategy":"fallback","validationCode":"client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)\nif err != nil || len(client.WindowIds) == 0 {\n    // do not call with WindowId \"current\"\n}","typeGuard":"func hasActiveWindow(c *waveobj.Client) bool {\n    return c != nil && len(c.WindowIds) > 0\n}","tryCatchPattern":"blocks, err := client.BlocksListCommand(ctx, wshrpc.CommandBlocksListData{WindowId: \"current\"})\nif err != nil && strings.Contains(err.Error(), \"no active window\") {\n    // fall back to explicit workspace/window ID or create a window first\n    return nil\n}","preventionTips":["Avoid WindowId \"current\" in headless/test contexts","Seed a client with windows in test fixtures","Pass explicit WindowId/WorkspaceId when state is uncertain"],"tags":["wsh","rpc","window-state","no-active-window"],"backgroundTag":"no-active-window","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}