Tencent/WeKnora · warning

cannot revert to the current version

Error message

cannot revert to the current version

What it means

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.

Source

Thrown at internal/application/service/wiki_page.go:280

func (s *wikiPageService) pruneRevisions(ctx context.Context, pageID string, currentVersion int) {
	req := types.WikiRevisionPruneRequest{
		PageID:              pageID,
		KeepFromVersion:     currentVersion - types.WikiMaxRevisionsPerPage,
		PrunableSources:     types.WikiPrunableEditSources,
		HardKeepFromVersion: currentVersion - types.WikiMaxRevisionsHardCap,
	}
	if req.KeepFromVersion <= 0 && req.HardKeepFromVersion <= 0 {
		return
	}
	if err := s.repo.PruneRevisions(ctx, req); err != nil {
		logger.Warnf(ctx, "prune wiki page revisions for %s failed: %v", pageID, err)
	}
}

// ErrWikiRevertToCurrentVersion is returned when a revert targets the version
// the page is already on — a client-side mistake (usually a stale history
// list), not a server fault, so handlers map it to 400.
var ErrWikiRevertToCurrentVersion = errors.New("cannot revert to the current version")

// ListRevisions returns the stored historical snapshots for a page (newest
// first, content omitted) plus the page's current version.
func (s *wikiPageService) ListRevisions(
	ctx context.Context, kbID string, slug string, limit int, offset int,
) (*types.WikiPageRevisionListResponse, error) {
	page, err := s.repo.GetBySlug(ctx, kbID, slug)
	if err != nil {
		return nil, err
	}
	revs, total, err := s.repo.ListRevisions(ctx, kbID, page.ID, limit, offset)
	if err != nil {
		return nil, fmt.Errorf("list wiki page revisions: %w", err)
	}
	return &types.WikiPageRevisionListResponse{
		Revisions:      revs,
		Total:          total,
		CurrentVersion: page.Version,

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Refresh the page history and revert to a version different from the current one.
  2. Handle errors.Is(err, ErrWikiRevertToCurrentVersion) in the client/UI as a no-op or friendly 400 message.
  3. Check the page's current version before requesting the revert.

Example fix

// before
_, err := h.svc.RevertPageToVersion(ctx, kbID, slug, targetVersion)
// after
page, _ := h.svc.GetPage(ctx, kbID, slug)
if page.Version == targetVersion {
    return httpError(400, "already on this version")
}
_, err := h.svc.RevertPageToVersion(ctx, kbID, slug, targetVersion)
Defensive patterns

Strategy: try-catch

Validate before calling

page, err := h.svc.GetPage(ctx, kbID, slug)
if err == nil && page.Version == targetVersion {
    return httpError(400, "page is already on this version")
}

Try / catch

// handler
if errors.Is(err, service.ErrWikiRevertToCurrentVersion) {
    return httpError(400, err.Error())
}

Prevention

When it happens

Trigger: 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.

Common situations: Two users revert concurrently; UI history list rendered before another revert landed; double-clicking the revert button for the same version.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/70e685e3a84bfb1c. Report an issue: GitHub.