siyuan-note/siyuan · error

invalid reorder position

Error message

invalid reorder position [%s]

What it means

The position argument of a document reorder must be exactly the string "before" or "after", indicating whether sources are placed before or after the target document. Any other string is rejected with this formatted error. The comparison is case-sensitive.

Solutions

  1. Send only the literal lowercase strings "before" or "after"
  2. Normalize/whitelist the position value at the call site before invoking the API
  3. Check the API documentation for the exact parameter contract and update the caller
  4. Map any other positioning concepts (e.g. 'inside', 'first') to the supported move APIs instead

Example fix

// before
reorderDocs(ids, targetID, dropZone) // e.g. "above"
// after
const pos = dropZone === "above" ? "before" : "after"
reorderDocs(ids, targetID, pos)
Defensive patterns

Strategy: validation

Validate before calling

if (position !== "before" && position !== "after") throw new Error(`position must be "before"|"after", got ${position}`)

Type guard

const isReorderPosition = (p) => p === "before" || p === "after"

Try / catch

try { await api.reorderDocs(src, targetID, pos) } catch (e) { if (String(e).includes("invalid reorder position")) { pos = pos.toLowerCase() === "before" ? "before" : "after"; return retryOnce() } throw e }

Prevention

When it happens

Trigger: Passing "Before", "top", "above", or a localized string as position; sending position as a number or enum instead of the literal strings; typo like "befor".

Common situations: Plugins mapping their own drop-zone labels to position values without normalizing; API scripts guessing the parameter vocabulary; UI code using "before"/"after" only in some branches.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/file.go:2746

		fileTreeSortLock.Unlock()
		return ret, writeErr
	}
	fileTreeSortLock.Unlock()

	ret.Changed = true
	ret.Notebook = box.ID
	ret.ParentPath = parentPath
	IncSync()
	pushFiletreeSortChanged(sortIDs)
	return
}

func validateReorderArgs(sourceIDs []string, targetID, position string) error {
	if 1 > len(sourceIDs) {
		return errors.New("source IDs must not be empty")
	}
	if "before" != position && "after" != position {
		return fmt.Errorf("invalid reorder position [%s]", position)
	}
	seen := map[string]struct{}{}
	for _, sourceID := range sourceIDs {
		if sourceID == targetID {
			return fmt.Errorf("target ID [%s] must not be included in source IDs", targetID)
		}
		if _, ok := seen[sourceID]; ok {
			return fmt.Errorf("duplicate source ID [%s]", sourceID)
		}
		seen[sourceID] = struct{}{}
	}
	return nil
}

func isSortableDocument(tree *treenode.BlockTree) bool {
	return nil != tree && tree.ID == tree.RootID && "d" == tree.Type && !IsBoxDoc(tree.BoxID, tree.RootID)
}

View on GitHub (pinned to 9f775e8a12)