siyuan-note/siyuan · error
failed to write file paths to pasteboard
Error message
failed to write file paths to pasteboard
What it means
The macOS cgo helper writeFilePathsToPasteboard returns a generic failure code (anything other than 0 or -2) when writing file paths to NSPasteboard fails. Go maps that to this opaque error; the underlying Cocoa error details are not propagated.
Solutions
- Retry the write once after a short delay (pasteboard may be transiently busy)
- Verify paths exist and are accessible, then retry
- If persistent, file/diagnose in the helper — the return code is unmapped so add logging around the C call
Example fix
// before
if err := util.WriteFilePaths(paths); err != nil { return err }
// after
if err := util.WriteFilePaths(paths); err != nil {
time.Sleep(50 * time.Millisecond)
if err2 := util.WriteFilePaths(paths); err2 != nil { return err2 }
} Defensive patterns
Strategy: retry
Validate before calling
for _, p := range paths { if _, err := os.Stat(p); err != nil { return err } } Try / catch
if err := util.WriteFilePaths(paths); err != nil {
time.Sleep(100 * time.Millisecond)
if retryErr := util.WriteFilePaths(paths); retryErr != nil {
// report persistent pasteboard failure
}
} Prevention
- Retry transient pasteboard writes once before surfacing the error
- Close apps that aggressively lock NSPasteboard
- Log the unmapped return code from the C helper to diagnose recurring failures
When it happens
Trigger: Calling util.WriteFilePaths on macOS when the NSPasteboard write fails — e.g. pasteboard unavailable, out of memory, or an unexpected return code from the Objective-C helper.
Common situations: Pasteboard contention with another app holding the pasteboard, sandboxed/oddly-permissioned environments, or a bug in the helper returning an unmapped code.
Related errors
- no valid file paths to write (invalid UTF-8 or path)
- directory assets are not supported in encrypted notebooks
- failed to read iCloud file resource status
- Field [assets. .box] should be of type [String]
- Field [assets. ] should be of type [Object]
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/61b57467bc73bc4e.
Report an issue: GitHub.
Appendix: 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 9f775e8a12)