siyuan-note/siyuan · error

source IDs must not be empty

Error message

source IDs must not be empty

What it means

validateReorderArgs enforces that a document reorder request carries at least one source document ID. An empty sourceIDs slice makes the operation meaningless and is rejected up front with this plain error. It runs before any tree lookups, so no documents are touched.

Solutions

  1. Guard the call site: skip the API call when the source list length is 0
  2. Ensure the UI selection is non-empty before enabling the reorder action
  3. Fix any pre-send filtering that can drain the array entirely
  4. Handle the empty case as a no-op rather than an error in your wrapper

Example fix

// before
reorderDocs(selectedIDs, targetID, pos) // may be empty
// after
if (selectedIDs.length > 0) {
    reorderDocs(selectedIDs, targetID, pos)
}
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(sourceIDs) || sourceIDs.length === 0) return // no-op, skip API call

Try / catch

try { await api.reorderDocs(src, targetID, pos) } catch (e) { if (String(e).includes("source IDs must not be empty")) return /* treat as no-op */; throw e }

Prevention

When it happens

Trigger: Calling the reorder API with sourceIDs: [] or null; frontend code invoking reorder after a selection was programmatically cleared.

Common situations: Drag-and-drop handlers firing with an empty selection; batch scripts looping until the source list is exhausted then issuing one final empty call; filters that removed all IDs before sending.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — 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/9ce35f119265810e. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/file.go:2743

	}
	maps.Copy(fullSortIDs, sortIDs)
	if writeErr := writeSortConfMap(confPath, fullSortIDs); nil != writeErr {
		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 {

View on GitHub (pinned to 9f775e8a12)