{"record":{"id":"8d1cc7aa90a148f0","repo":"siyuan-note/siyuan","slug":"invalid-utf-8-path","errorCode":null,"errorMessage":"invalid UTF-8 path","messagePattern":"invalid UTF-8 path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/icloud_darwin.go","lineNumber":59,"sourceCode":"*/\nimport \"C\"\n\nimport (\n\t\"errors\"\n\t\"unsafe\"\n)\n\nfunc isUbiquitousItem(path string) (bool, error) {\n\tcPath := C.CString(path)\n\tdefer C.free(unsafe.Pointer(cPath))\n\n\tswitch C.siyuanIsUbiquitousItem(cPath) {\n\tcase 1:\n\t\treturn true, nil\n\tcase 0:\n\t\treturn false, nil\n\tcase -2:\n\t\treturn false, errors.New(\"invalid UTF-8 path\")\n\tdefault:\n\t\treturn false, errors.New(\"failed to read iCloud file resource status\")\n\t}\n}\n","sourceCodeStart":41,"sourceCodeEnd":64,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/icloud_darwin.go#L41-L64","documentation":"isUbiquitousItem on macOS calls the C helper siyuanIsUbiquitousItem with a UTF-8 encoded path to query iCloud (ubiquitous) resource status. The C layer returns -2 when the Go string cannot be converted to a valid C string, i.e. the path is not valid UTF-8. Go then surfaces this as \"invalid UTF-8 path\" instead of calling into Foundation with garbage data.","triggerScenarios":"Calling isUbiquitousItem (directly or via iCloud-related file checks) with a path containing invalid UTF-8 bytes — typically filenames created on other filesystems with legacy encodings, or paths built from corrupted/untrusted input.","commonSituations":"Syncing notebooks from Windows/FAT/exFAT volumes where filenames were stored in non-UTF-8 encodings; data imported from archives with mangled names; paths assembled from user input containing raw bytes; corrupted .sy-adjacent asset filenames.","solutions":["Inspect the offending path and locate the invalid byte sequence (e.g. with utf8.ValidString)","Rename the file to a valid UTF-8 name (or restore it from a clean backup/sync copy)","Sanitize paths before passing them to iCloud checks — reject or transliterate non-UTF-8 names at ingestion time","If the file is unneeded, remove it so sync/iCloud scans no longer encounter it"],"exampleFix":"// before\nisUbiquitousItem(rawPath) // rawPath contains invalid bytes\n// after\nif !utf8.ValidString(rawPath) {\n    return fmt.Errorf(\"skipping non-UTF-8 path: %q\", rawPath)\n}\nisUbiquitousItem(rawPath)","handlingStrategy":"validation","validationCode":"func validUTF8Path(p string) bool { return utf8.ValidString(p) }\n// call before isUbiquitousItem","typeGuard":"func isSafePath(p string) bool { return p != \"\" && utf8.ValidString(p) }","tryCatchPattern":"if err != nil && err.Error() == \"invalid UTF-8 path\" {\n    // log and skip the path; offer to rename the file\n}","preventionTips":["Validate utf8.ValidString on every path entering iCloud checks","Normalize filenames to UTF-8 at import/sync ingestion","Rename or remove legacy-encoded filenames on shared volumes"],"tags":["icloud","macos","encoding","filesystem"],"backgroundTag":"invalid-argument-format","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"}