{"record":{"id":"70e685e3a84bfb1c","repo":"Tencent/WeKnora","slug":"cannot-revert-to-the-current-version","errorCode":null,"errorMessage":"cannot revert to the current version","messagePattern":"cannot revert to the current version","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/application/service/wiki_page.go","lineNumber":280,"sourceCode":"func (s *wikiPageService) pruneRevisions(ctx context.Context, pageID string, currentVersion int) {\n\treq := types.WikiRevisionPruneRequest{\n\t\tPageID:              pageID,\n\t\tKeepFromVersion:     currentVersion - types.WikiMaxRevisionsPerPage,\n\t\tPrunableSources:     types.WikiPrunableEditSources,\n\t\tHardKeepFromVersion: currentVersion - types.WikiMaxRevisionsHardCap,\n\t}\n\tif req.KeepFromVersion <= 0 && req.HardKeepFromVersion <= 0 {\n\t\treturn\n\t}\n\tif err := s.repo.PruneRevisions(ctx, req); err != nil {\n\t\tlogger.Warnf(ctx, \"prune wiki page revisions for %s failed: %v\", pageID, err)\n\t}\n}\n\n// ErrWikiRevertToCurrentVersion is returned when a revert targets the version\n// the page is already on — a client-side mistake (usually a stale history\n// list), not a server fault, so handlers map it to 400.\nvar ErrWikiRevertToCurrentVersion = errors.New(\"cannot revert to the current version\")\n\n// ListRevisions returns the stored historical snapshots for a page (newest\n// first, content omitted) plus the page's current version.\nfunc (s *wikiPageService) ListRevisions(\n\tctx context.Context, kbID string, slug string, limit int, offset int,\n) (*types.WikiPageRevisionListResponse, error) {\n\tpage, err := s.repo.GetBySlug(ctx, kbID, slug)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trevs, total, err := s.repo.ListRevisions(ctx, kbID, page.ID, limit, offset)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"list wiki page revisions: %w\", err)\n\t}\n\treturn &types.WikiPageRevisionListResponse{\n\t\tRevisions:      revs,\n\t\tTotal:          total,\n\t\tCurrentVersion: page.Version,","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L262-L298","documentation":"ErrWikiRevertToCurrentVersion is returned when a revert operation targets the exact version the page is already on. Per its doc comment, this is a client-side mistake (usually a stale history list) rather than a server fault, and handlers map it to HTTP 400. Reverting to the current version would be a no-op, so the service rejects it explicitly.","triggerScenarios":"Calling RevertPageToVersion/RevertPage with a version number equal to page.Version for the given kbID and slug — typically after the page was already reverted or updated while the client's history list was open.","commonSituations":"Two users revert concurrently; UI history list rendered before another revert landed; double-clicking the revert button for the same version.","solutions":["Refresh the page history and revert to a version different from the current one.","Handle errors.Is(err, ErrWikiRevertToCurrentVersion) in the client/UI as a no-op or friendly 400 message.","Check the page's current version before requesting the revert."],"exampleFix":"// before\n_, err := h.svc.RevertPageToVersion(ctx, kbID, slug, targetVersion)\n// after\npage, _ := h.svc.GetPage(ctx, kbID, slug)\nif page.Version == targetVersion {\n    return httpError(400, \"already on this version\")\n}\n_, err := h.svc.RevertPageToVersion(ctx, kbID, slug, targetVersion)","handlingStrategy":"try-catch","validationCode":"page, err := h.svc.GetPage(ctx, kbID, slug)\nif err == nil && page.Version == targetVersion {\n    return httpError(400, \"page is already on this version\")\n}","typeGuard":null,"tryCatchPattern":"// handler\nif errors.Is(err, service.ErrWikiRevertToCurrentVersion) {\n    return httpError(400, err.Error())\n}","preventionTips":["Refresh the history list after each revert before allowing another.","Disable the revert button for the row matching the current version.","Map this sentinel to 400, never 500, in the HTTP layer."],"tags":["validation","wiki","revert","client-error"],"backgroundTag":"no-op-conflict","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}