siyuan-note/siyuan · error

target ID [ ] is not in the current order

Error message

target ID [%s] is not in the current order

What it means

When applying a custom sort, the function validates that the targetID (the block the dragged items are dropped before/after) exists in the current sibling order list. If targetID is absent from currentIDs, it refuses with "target ID [%s] is not in the current order". This guards against moving items relative to a sibling that no longer exists or was never part of this parent.

Solutions

  1. Reload the sibling order from the backend and retry the sort with a fresh currentIDs list and targetID
  2. Confirm the targetID is the root document ID of a sibling in the same parent (see error 1399's stricter checks)
  3. Remove stale sort requests in the frontend after document deletion/move operations

Example fix

// before: stale targetID from cached UI
MoveDocsSort(sourceIDs, staleTargetID, pos)
// after: validate target is still a current sibling
currentIDs, _ := loadSiblingCustomOrder(boxID, parentPath, nil)
if !slices.Contains(currentIDs, targetID) {
    targetID = currentIDs[len(currentIDs)-1] // fall back to last sibling
}
MoveDocsSort(sourceIDs, targetID, pos)
Defensive patterns

Strategy: validation

Validate before calling

const currentIDs = await api.getChildDocs(parentID);
if (!currentIDs.includes(targetID)) throw new Error('stale targetID');

Type guard

const isValidTarget = (id, currentIDs) => typeof id === 'string' && currentIDs.includes(id);

Try / catch

try { await api.sortDocs(sources, targetID, pos); } catch (e) { if (String(e).includes('not in the current order')) { await refreshSortModel(); retry(); } else { throw e; } }

Prevention

When it happens

Trigger: Calling the sort-application API with a targetID that is not among currentIDs — e.g. the target document was deleted or moved to another parent after the frontend built the sort request, or the targetID belongs to a different parent directory's order.

Common situations: Stale UI state: user sorted a second list view while the first request's target was deleted; concurrent edits in two windows; frontend passes a block ID (heading/child) instead of the root document ID; IDs from an old snapshot after syncing.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c3a426fe8802cda1. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/file.go:2812

func mergeRequestedSortOrder(currentIDs, requestedPaths []string) (ret []string) {
	requestedIDs := make([]string, 0, len(requestedPaths))
	for _, requestedPath := range requestedPaths {
		requestedIDs = append(requestedIDs, util.GetTreeID(requestedPath))
	}
	return mergeRequestedIDOrder(currentIDs, requestedIDs)
}

func reorderIDSequence(currentIDs, sourceIDs []string, targetID, position string) (ret []string, changed bool, err error) {
	if err = validateReorderArgs(sourceIDs, targetID, position); nil != err {
		return
	}
	currentSet := make(map[string]struct{}, len(currentIDs))
	for _, id := range currentIDs {
		currentSet[id] = struct{}{}
	}
	if _, exists := currentSet[targetID]; !exists {
		return nil, false, fmt.Errorf("target ID [%s] is not in the current order", targetID)
	}
	sourceSet := make(map[string]struct{}, len(sourceIDs))
	for _, sourceID := range sourceIDs {
		if _, exists := currentSet[sourceID]; !exists {
			return nil, false, fmt.Errorf("source ID [%s] is not in the current order", sourceID)
		}
		sourceSet[sourceID] = struct{}{}
	}
	remaining := make([]string, 0, len(currentIDs)-len(sourceIDs))
	for _, id := range currentIDs {
		if _, source := sourceSet[id]; !source {
			remaining = append(remaining, id)
		}
	}
	targetIndex := -1
	for i, id := range remaining {
		if id == targetID {
			targetIndex = i

View on GitHub (pinned to 9f775e8a12)