siyuan-note/siyuan · error

failed to write file paths to pasteboard

Error message

failed to write file paths to pasteboard

What it means

Returned on macOS when the embedded Objective-C writeFilePathsToPasteboard returns -1, i.e. [NSPasteboard.generalPasteboard writeObjects:] returned NO after clearContents. At that point paths were valid enough to build the array, but the pasteboard rejected the write. This is a system-level failure, not an input-validation one.

Source

Thrown at kernel/util/clipboard_darwin.go:102

	// 分配 C 的 char* 数组,便于传入 Objective-C
	cPaths := make([]*C.char, len(paths))
	for i, p := range paths {
		cPaths[i] = C.CString(p)
	}
	defer func() {
		for _, c := range cPaths {
			C.free(unsafe.Pointer(c))
		}
	}()
	// 取首元素地址作为 const char** 传入
	ret := C.writeFilePathsToPasteboard((**C.char)(unsafe.Pointer(&cPaths[0])), C.int(len(paths)))
	switch ret {
	case 0:
		return nil
	case -2:
		return errors.New("no valid file paths to write (invalid UTF-8 or path)")
	default:
		return errors.New("failed to write file paths to pasteboard")
	}
}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Retry the operation once after a short delay (pasteboard writeObjects: failures are often transient).
  2. Check Console.app for AppKit/pboard errors at the moment of failure to identify the system cause.
  3. If running sandboxed, verify the app has the pasteboard entitlement / is not in a hardened-restricted mode that blocks writes.

Example fix

// before
return util.WriteFilePaths(paths)

// after
var err error
for attempt := 0; attempt < 2; attempt++ {
    if err = util.WriteFilePaths(paths); err == nil {
        return nil
    }
    time.Sleep(100 * time.Millisecond)
}
return err
Defensive patterns

Strategy: retry

Try / catch

var err error
for attempt := 0; attempt < 2; attempt++ {
    if err = util.WriteFilePaths(paths); err == nil || !strings.Contains(err.Error(), "failed to write file paths to pasteboard") {
        break
    }
    time.Sleep(150 * time.Millisecond)
}

Prevention

When it happens

Trigger: Calling WriteFilePaths on macOS at a moment the general pasteboard cannot accept objects: very low memory, a pasteboard server (pboard) that is unresponsive, or a sandbox/entitlement restriction blocking pasteboard writes.

Common situations: Running under a restricted sandbox profile without the required entitlement; the pboard daemon temporarily unavailable; transient system resource exhaustion during a large copy operation.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/61b57467bc73bc4e. Report an issue: GitHub.