{"record":{"id":"61b57467bc73bc4e","repo":"siyuan-note/siyuan","slug":"failed-to-write-file-paths-to-pasteboard","errorCode":null,"errorMessage":"failed to write file paths to pasteboard","messagePattern":"failed to write file paths to pasteboard","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/clipboard_darwin.go","lineNumber":102,"sourceCode":"\t// 分配 C 的 char* 数组，便于传入 Objective-C\n\tcPaths := make([]*C.char, len(paths))\n\tfor i, p := range paths {\n\t\tcPaths[i] = C.CString(p)\n\t}\n\tdefer func() {\n\t\tfor _, c := range cPaths {\n\t\t\tC.free(unsafe.Pointer(c))\n\t\t}\n\t}()\n\t// 取首元素地址作为 const char** 传入\n\tret := C.writeFilePathsToPasteboard((**C.char)(unsafe.Pointer(&cPaths[0])), C.int(len(paths)))\n\tswitch ret {\n\tcase 0:\n\t\treturn nil\n\tcase -2:\n\t\treturn errors.New(\"no valid file paths to write (invalid UTF-8 or path)\")\n\tdefault:\n\t\treturn errors.New(\"failed to write file paths to pasteboard\")\n\t}\n}\n","sourceCodeStart":84,"sourceCodeEnd":105,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/clipboard_darwin.go#L84-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running under a restricted sandbox profile without the required entitlement; the pboard daemon temporarily unavailable; transient system resource exhaustion during a large copy operation.","solutions":["Retry the operation once after a short delay (pasteboard writeObjects: failures are often transient).","Check Console.app for AppKit/pboard errors at the moment of failure to identify the system cause.","If running sandboxed, verify the app has the pasteboard entitlement / is not in a hardened-restricted mode that blocks writes."],"exampleFix":"// before\nreturn util.WriteFilePaths(paths)\n\n// after\nvar err error\nfor attempt := 0; attempt < 2; attempt++ {\n    if err = util.WriteFilePaths(paths); err == nil {\n        return nil\n    }\n    time.Sleep(100 * time.Millisecond)\n}\nreturn err","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var err error\nfor attempt := 0; attempt < 2; attempt++ {\n    if err = util.WriteFilePaths(paths); err == nil || !strings.Contains(err.Error(), \"failed to write file paths to pasteboard\") {\n        break\n    }\n    time.Sleep(150 * time.Millisecond)\n}","preventionTips":["Treat this as a transient system error and retry before reporting failure.","Check Console.app for pboard/AppKit errors if retries keep failing."],"tags":["clipboard","macos","cgo","system"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}