{"record":{"id":"539ecd5c17847751","repo":"wavetermdev/waveterm","slug":"error-creating-workspace-w","errorCode":null,"errorMessage":"error creating workspace: %w","messagePattern":"error creating workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/service/workspaceservice/workspaceservice.go","lineNumber":34,"sourceCode":"\t\"github.com/wavetermdev/waveterm/pkg/wps\"\n\t\"github.com/wavetermdev/waveterm/pkg/wstore\"\n)\n\nconst DefaultTimeout = 2 * time.Second\n\ntype WorkspaceService struct{}\n\nfunc (svc *WorkspaceService) CreateWorkspace_Meta() tsgenmeta.MethodMeta {\n\treturn tsgenmeta.MethodMeta{\n\t\tArgNames:   []string{\"ctx\", \"name\", \"icon\", \"color\", \"applyDefaults\"},\n\t\tReturnDesc: \"workspaceId\",\n\t}\n}\n\nfunc (svc *WorkspaceService) CreateWorkspace(ctx context.Context, name string, icon string, color string, applyDefaults bool) (string, error) {\n\tnewWS, err := wcore.CreateWorkspace(ctx, name, icon, color, applyDefaults, false)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating workspace: %w\", err)\n\t}\n\treturn newWS.OID, nil\n}\n\nfunc (svc *WorkspaceService) UpdateWorkspace_Meta() tsgenmeta.MethodMeta {\n\treturn tsgenmeta.MethodMeta{\n\t\tArgNames: []string{\"ctx\", \"workspaceId\", \"name\", \"icon\", \"color\", \"applyDefaults\"},\n\t}\n}\n\nfunc (svc *WorkspaceService) UpdateWorkspace(ctx context.Context, workspaceId string, name string, icon string, color string, applyDefaults bool) (waveobj.UpdatesRtnType, error) {\n\tctx = waveobj.ContextWithUpdates(ctx)\n\t_, updated, err := wcore.UpdateWorkspace(ctx, workspaceId, name, icon, color, applyDefaults)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error updating workspace: %w\", err)\n\t}\n\tif !updated {\n\t\treturn nil, nil","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/service/workspaceservice/workspaceservice.go#L16-L52","documentation":"WorkspaceService.CreateWorkspace creates a workspace via wcore.CreateWorkspace and wraps failures with this error. wcore validates the name/icon/color inputs and persists a new Workspace object; this error means one of those steps failed (invalid input, duplicate/invalid name handling, or a persistence error).","triggerScenarios":"CreateWorkspace called with empty/invalid name, invalid icon or color strings, with an applyDefaults value driving a defaults-application failure, or when the underlying wstore insert of the new Workspace object fails.","commonSituations":"Frontend allowing empty workspace names through UI validation gaps; scripts calling the RPC directly with ad-hoc color/icon strings; DB errors or concurrent creation conflicts; calls with applyDefaults semantics changed in a newer backend.","solutions":["Unwrap the %w error to identify whether it was input validation or persistence that failed","Ensure name is non-empty and icon/color are valid per wcore's validation (valid icon name and color string) before calling","Handle persistence errors by checking DB health / retrying transient failures once","If applying defaults fails, try applyDefaults=false and apply configuration manually to isolate the failing step"],"exampleFix":"// before\nWorkspaceService.CreateWorkspace(ctx, \"\", \"bogus-icon\", \"#zzz\", true)\n// after\nWorkspaceService.CreateWorkspace(ctx, \"dev\", \"terminal\", \"#5d4037\", true)","handlingStrategy":"validation","validationCode":"function validateWorkspaceInput(name, icon, color) {\n  if (!name || !name.trim()) throw new Error(\"workspace name required\");\n  if (!icon || !color) throw new Error(\"icon and color required\");\n}","typeGuard":"function isValidWorkspaceCreateInput(i: { name: string; icon: string; color: string }): i is { name: string; icon: string; color: string } {\n  return i.name.trim().length > 0 && i.icon.length > 0 && /^#[0-9a-fA-F]{3,8}$|^\\w+$/.test(i.color);\n}","tryCatchPattern":"oid, err := WorkspaceService.CreateWorkspace(ctx, name, icon, color, applyDefaults)\nif err != nil {\n    return fmt.Errorf(\"create workspace: %w\", err)\n}","preventionTips":["Enforce non-empty name and valid icon/color in the UI before dispatching the RPC","Reject whitespace-only names client-side","Distinguish validation vs persistence failures by unwrapping the returned error"],"tags":["workspace","creation","validation"],"backgroundTag":"object-creation-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}