siyuan-note/siyuan · error

source document [ ] is unavailable

Error message

source document [%s] is unavailable

What it means

ReorderDocTree validates each requested source ID the same way as the target: it must resolve to a sortable root document in an opened notebook. If any source fails this check, the whole reorder is rejected atomically — no partial moves are applied.

Solutions

  1. Prune sourceIDs to currently existing root document IDs before calling
  2. Open the notebooks of all source documents
  3. Re-fetch the selection from the current file tree to avoid stale IDs

Example fix

// before
api.post('/api/filetree/reorderDocs', {sourceIDs: selected, targetID, position})
// after
const valid = []
for (const id of selected) if (await isRootDoc(id)) valid.push(id)
api.post('/api/filetree/reorderDocs', {sourceIDs: valid, targetID, position})
Defensive patterns

Strategy: validation

Validate before calling

const validSources = sourceIDs.filter(id => { const bt = getBlockTree(id); return bt && bt.type === 'd' && bt.rootID === bt.id && isOpenedNotebook(bt.boxID) })

Type guard

const isSortableSource = (bt) => !!bt && bt.type === 'd' && bt.rootID === bt.id;

Try / catch

try { await reorderDocs(sourceIDs, targetID, pos) } catch (e) { if (/source document .* is unavailable/.test(e)) { dropInvalidSources(); await retry() } }

Prevention

When it happens

Trigger: Calling ReorderDocTree with a sourceIDs entry that is missing from the block tree, is not a root 'd' block, or belongs to a notebook that is not opened (Conf.Box == nil).

Common situations: Multi-select drag where one selected document was deleted meanwhile; passing child block IDs; dragging across from a closed notebook.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/file_tree_reorder.go:153

	currentIDs := make([]string, 0, len(docs))
	for _, doc := range docs {
		byID[doc.ID] = doc
		currentIDs = append(currentIDs, doc.ID)
	}
	siblingIDs, err := loadSiblingCustomOrder(box.ID, parentDir, existingSorts)
	if err != nil {
		return nil, err
	}
	for _, id := range siblingIDs {
		if byID[id] == nil {
			return nil, fmt.Errorf("document [%s] could not be read", id)
		}
	}
	var fromPaths []string
	for _, id := range sourceIDs {
		source := treenode.GetBlockTree(id)
		if !isSortableDocument(source) || Conf.Box(source.BoxID) == nil {
			return nil, fmt.Errorf("source document [%s] is unavailable", id)
		}
		if source.BoxID == target.BoxID && (target.Path == source.Path ||
			strings.HasPrefix(target.Path, strings.TrimSuffix(source.Path, ".sy")+"/")) {
			return nil, errors.New(Conf.Language(87))
		}
		if byID[id] != nil {
			continue
		}
		sourceParent := path.Dir(source.Path)
		if sourceParent != "/" {
			sourceParent += ".sy"
		}
		sourceDocs, _, loadErr := ListDocTree(source.BoxID, sourceParent, util.SortModeCustom, false, true, int(^uint(0)>>1))
		if loadErr != nil {
			return nil, loadErr
		}
		for _, doc := range sourceDocs {
			if doc.ID == id {

View on GitHub (pinned to 9f775e8a12)