{"record":{"id":"490ae2b31d4e4315","repo":"wavetermdev/waveterm","slug":"error-creating-workspace-w-490ae2","errorCode":null,"errorMessage":"error creating workspace: %w","messagePattern":"error creating workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wcore/window.go","lineNumber":87,"sourceCode":"\treturn ws, nil\n}\n\nfunc GetWindow(ctx context.Context, windowId string) (*waveobj.Window, error) {\n\twindow, err := wstore.DBMustGet[*waveobj.Window](ctx, windowId)\n\tif err != nil {\n\t\tlog.Printf(\"error getting window %q: %v\\n\", windowId, err)\n\t\treturn nil, err\n\t}\n\treturn window, nil\n}\n\nfunc CreateWindow(ctx context.Context, winSize *waveobj.WinSize, workspaceId string) (*waveobj.Window, error) {\n\tlog.Printf(\"CreateWindow %v %v\\n\", winSize, workspaceId)\n\tvar ws *waveobj.Workspace\n\tif workspaceId == \"\" {\n\t\tws1, err := CreateWorkspace(ctx, \"\", \"\", \"\", false, false)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error creating workspace: %w\", err)\n\t\t}\n\t\tws = ws1\n\t} else {\n\t\tws1, err := GetWorkspace(ctx, workspaceId)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error getting workspace: %w\", err)\n\t\t}\n\t\tws = ws1\n\t}\n\twindowId := uuid.NewString()\n\tif winSize == nil {\n\t\twinSize = &waveobj.WinSize{\n\t\t\tWidth:  0,\n\t\t\tHeight: 0,\n\t\t}\n\t}\n\twindow := &waveobj.Window{\n\t\tOID:         windowId,","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wcore/window.go#L69-L105","documentation":"CreateWindow with an empty workspaceId first creates a brand-new workspace via CreateWorkspace; this error wraps any failure of that creation. The window itself is never created, so callers receive nil and must handle the wrapped DB error.","triggerScenarios":"wcore.CreateWindow(ctx, winSize, \"\") when the internal CreateWorkspace(ctx, \"\", \"\", \"\", false, false) fails — DB insert error for the new workspace object, DB unavailable, or singleton/client setup failure.","commonSituations":"First-launch bootstrap when the state DB cannot be written (permissions on ~/.waveterm, read-only disk); corrupted DB rejecting inserts; EnsureInitialData racing with another startup path creating client/workspace singletons.","solutions":["Inspect the wrapped %w error for the root DB failure","Verify the waveterm state directory is writable and the DB is not corrupted","Ensure only one initialization path runs at startup (avoid concurrent EnsureInitialData/CreateWindow)","Retry window creation after the DB is accessible"],"exampleFix":"// before\nws1, err := CreateWorkspace(ctx, \"\", \"\", \"\", false, false)\nif err != nil {\n\treturn nil, fmt.Errorf(\"error creating workspace: %w\", err)\n}\n// after\nws1, err := CreateWorkspace(ctx, \"\", \"\", \"\", false, false)\nif err != nil {\n\treturn nil, fmt.Errorf(\"error creating workspace for new window: %w\", err)\n}\nlog.Printf(\"created workspace %s for new window\", ws1.OID)","handlingStrategy":"retry","validationCode":"wsList, err := wstore.DBGetAllObjsByType[*waveobj.Workspace](ctx, waveobj.OType_Workspace)\nif err != nil {\n\treturn fmt.Errorf(\"DB not readable, cannot create window: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"win, err := wcore.CreateWindow(ctx, winSize, \"\")\nif err != nil {\n\tif strings.Contains(err.Error(), \"error creating workspace\") {\n\t\ttime.Sleep(200 * time.Millisecond)\n\t\twin, err = wcore.CreateWindow(ctx, winSize, \"\") // one retry\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n}","preventionTips":["Run EnsureInitialData before any window creation","Check the wavetem state dir is writable at startup","Avoid multiple processes sharing one waveterm state DB"],"tags":["database","wave-terminal","workspace","window-creation"],"backgroundTag":"database-insert-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}