{"record":{"id":"9d88e2de630b4dee","repo":"siyuan-note/siyuan","slug":"no-valid-file-paths-to-write-invalid-utf-8-or-pat","errorCode":null,"errorMessage":"no valid file paths to write (invalid UTF-8 or path)","messagePattern":"no valid file paths to write \\(invalid UTF-8 or path\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/clipboard_darwin.go","lineNumber":100,"sourceCode":"\t\treturn nil\n\t}\n\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":82,"sourceCodeEnd":105,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/clipboard_darwin.go#L82-L105","documentation":"On macOS, WriteFilePaths marshals each path to a NUL-terminated C string and calls writeFilePathsToPasteboard via cgo. The Objective-C helper returns -2 when none of the supplied paths could be converted/validated — typically invalid UTF-8 in a path or an unusable path string — so the pasteboard write is aborted.","triggerScenarios":"Calling util.WriteFilePaths with a []string containing non-UTF-8 bytes (Go strings can hold arbitrary bytes) so the conversion to const char* fails for every path, or an empty/nil slice reaching the C helper.","commonSituations":"File names read from disk with non-UTF-8 encodings (e.g. legacy NFD/HFS+ or Latin-1 names) being pushed to the clipboard; paths built from raw byte buffers.","solutions":["Validate each path is valid UTF-8 before calling: skip or convert strings where !utf8.ValidString(p)","Normalize problematic names (golang.org/x/text/encoding or unicode/norm) before clipboard write","Ensure the slice is non-empty and every element is a real filesystem path"],"exampleFix":"// before\nutil.WriteFilePaths(rawPaths) // contains invalid UTF-8\n// after\nvar valid []string\nfor _, p := range rawPaths {\n    if utf8.ValidString(p) { valid = append(valid, p) }\n}\nif len(valid) > 0 { util.WriteFilePaths(valid) }","handlingStrategy":"validation","validationCode":"func allValidUTF8(paths []string) bool {\n    for _, p := range paths {\n        if !utf8.ValidString(p) || p == \"\" { return false }\n    }\n    return len(paths) > 0\n}","typeGuard":"func isClipboardReadyPath(p string) bool { return p != \"\" && utf8.ValidString(p) }","tryCatchPattern":"if err := util.WriteFilePaths(paths); err != nil {\n    if strings.Contains(err.Error(), \"no valid file paths\") {\n        // sanitize/normalize paths and retry\n    }\n}","preventionTips":["Validate utf8.ValidString on every path before clipboard writes","Normalize filenames with unicode/norm or x/text when read from legacy filesystems","Never pass raw byte-slice-derived strings as paths without validation"],"tags":["clipboard","macos","utf-8","cgo"],"backgroundTag":"invalid-argument-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}