{"record":{"id":"0fc361e43d4f391a","repo":"Tencent/WeKnora","slug":"create-wiki-folder-q-w","errorCode":null,"errorMessage":"create wiki folder %q: %w","messagePattern":"create wiki folder %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/wiki_page.go","lineNumber":1586,"sourceCode":"\t\t\t}\n\t\t\tnow := time.Now()\n\t\t\tchild = &types.WikiFolder{\n\t\t\t\tID:              uuid.New().String(),\n\t\t\t\tTenantID:        tenantID,\n\t\t\t\tKnowledgeBaseID: kbID,\n\t\t\t\tParentID:        parentID,\n\t\t\t\tName:            name,\n\t\t\t\tPath:            fp,\n\t\t\t\tDepth:           depth + 1,\n\t\t\t\tCreatedAt:       now,\n\t\t\t\tUpdatedAt:       now,\n\t\t\t}\n\t\t\tif cerr := s.repo.CreateFolder(ctx, child); cerr != nil {\n\t\t\t\t// Lost a create race (or unique violation): the sibling must\n\t\t\t\t// now exist — re-fetch it rather than failing the whole plan.\n\t\t\t\tchild, err = s.repo.GetChildFolderByName(ctx, kbID, parentID, name)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn \"\", nil, fmt.Errorf(\"create wiki folder %q: %w\", fp, cerr)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tparentID = child.ID\n\t\tparentPath = child.Path\n\t}\n\treturn parentID, clean, nil\n}\n\n// MovePage relocates a page into folderID (\"\" = root) and refreshes its cached\n// category path. Bookkeeping-only write (no version bump).\nfunc (s *wikiPageService) MovePage(\n\tctx context.Context, kbID string, slug string, folderID string,\n) (*types.WikiPage, error) {\n\tpage, err := s.repo.GetBySlug(ctx, kbID, slug)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":1568,"sourceCodeEnd":1604,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L1568-L1604","documentation":"FindOrCreateFolderPath wraps repo.CreateFolder failure only when the post-race re-fetch (GetChildFolderByName) also fails — i.e., a genuine create error, not a lost race. The folder path (and the move/plan depending on it) cannot be established.","triggerScenarios":"Thrown at internal/application/service/wiki_page.go:1586 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped create error (constraints, DB down)","Check for name/path conflicts on the sibling folder","Retry; concurrent creators resolve via the re-fetch path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}