{"record":{"id":"5bc3a8deba8ee763","repo":"wavetermdev/waveterm","slug":"error-creating-tab-w","errorCode":null,"errorMessage":"error creating tab: %w","messagePattern":"error creating tab: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/service/workspaceservice/workspaceservice.go","lineNumber":155,"sourceCode":"}\n\nfunc (svc *WorkspaceService) GetIcons_Meta() tsgenmeta.MethodMeta {\n\treturn tsgenmeta.MethodMeta{\n\t\tReturnDesc: \"icons\",\n\t}\n}\n\nfunc (svc *WorkspaceService) GetIcons() []string {\n\treturn wcore.WorkspaceIcons[:]\n}\n\nfunc (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activateTab bool) (string, waveobj.UpdatesRtnType, error) {\n\tctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancelFn()\n\tctx = waveobj.ContextWithUpdates(ctx)\n\ttabId, err := wcore.CreateTab(ctx, workspaceId, tabName, activateTab, false)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"error creating tab: %w\", err)\n\t}\n\tupdates := waveobj.ContextGetUpdatesRtn(ctx)\n\tgo func() {\n\t\tdefer func() {\n\t\t\tpanichandler.PanicHandler(\"WorkspaceService:CreateTab:SendUpdateEvents\", recover())\n\t\t}()\n\t\twps.Broker.SendUpdateEvents(updates)\n\t}()\n\treturn tabId, updates, nil\n}\n\nfunc (svc *WorkspaceService) SetActiveTab_Meta() tsgenmeta.MethodMeta {\n\treturn tsgenmeta.MethodMeta{\n\t\tArgNames: []string{\"workspaceId\", \"tabId\"},\n\t}\n}\n\nfunc (svc *WorkspaceService) SetActiveTab(workspaceId string, tabId string) (waveobj.UpdatesRtnType, error) {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/service/workspaceservice/workspaceservice.go#L137-L173","documentation":"CreateTab is the RPC service wrapper around wcore.CreateTab, which inserts a new Tab object into the workspace and persists it. When the core creation fails for any reason (bad workspace id, DB error, missing workspace), the error is wrapped with \"error creating tab: %w\" and returned to the RPC caller. The %w wrapping preserves the underlying cause for errors.Is/As inspection.","triggerScenarios":"Calling CreateTab(workspaceId, tabName, activateTab) with a workspaceId that does not exist in the DB, or when the underlying wcore.CreateTab fails due to storage/transaction errors or context timeout (DefaultTimeout exceeded).","commonSituations":"Stale workspace references after a workspace was deleted in another client, corrupted wave DB, or slow disk causing the context timeout.","solutions":["Check that the workspaceId passed exists (wstore.DBGet[*waveobj.Workspace]) before calling CreateTab","Unwrap the error with errors.Unwrap / %w chain to see the root cause from wcore.CreateTab","Verify the wave DB file is writable and not corrupted","Check for context timeout (DefaultTimeout) issues on slow storage"],"exampleFix":"// before\ntabId, err := svc.CreateTab(\"ws-does-not-exist\", \"New Tab\", true)\n// after\nws, err := wstore.DBGet[*waveobj.Workspace](ctx, \"ws-does-not-exist\")\nif err != nil { return fmt.Errorf(\"workspace not found: %w\", err) }\ntabId, err := svc.CreateTab(ws.OID, \"New Tab\", true)","handlingStrategy":"validation","validationCode":"if _, err := wstore.DBGet[*waveobj.Workspace](ctx, workspaceId); err != nil {\n    return fmt.Errorf(\"cannot create tab: workspace %s not found: %w\", workspaceId, err)\n}\ntabId, err := svc.CreateTab(workspaceId, tabName, activateTab)","typeGuard":null,"tryCatchPattern":"tabId, err := svc.CreateTab(workspaceId, tabName, activateTab)\nif err != nil {\n    var notFound *waveobj.ErrNotFound\n    if errors.As(err, &notFound) { /* refresh workspace list */ }\n    return fmt.Errorf(\"create tab failed: %w\", err)\n}","preventionTips":["Validate workspaceId existence before creating tabs","Keep the client's workspace state in sync after delete operations","Log the unwrapped cause chain for diagnosis"],"tags":["go","workspace","tab","rpc"],"backgroundTag":"wrapped-error-propagation","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}