siyuan-note/siyuan · error
no valid file paths to write (invalid UTF-8 or path)
Error message
no valid file paths to write (invalid UTF-8 or path)
What it means
Returned on macOS when the embedded Objective-C writeFilePathsToPasteboard returns -2, meaning the NSMutableArray of NSURL objects ended up empty. That happens only if every input path produced a nil NSString (invalid UTF-8 bytes) or a nil NSURL (path rejected by fileURLWithPath:). The Go side translates -2 into this message.
Source
Thrown at kernel/util/clipboard_darwin.go:100
return nil
}
// 分配 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
- Validate every path with utf8.ValidString and filepath.Clean before calling WriteFilePaths, and drop empty strings.
- Confirm the caller (kernel/api/clipboard.go:90) is passing a resolved absolute path from model.GetAssetAbsPathInBox rather than a relative or malformed one.
- Check for NUL bytes or other control characters in the path and reject them upstream.
Example fix
// before
util.WriteFilePaths(paths)
// after
var clean []string
for _, p := range paths {
if p == "" || !utf8.ValidString(p) || strings.ContainsRune(p, 0) {
continue
}
clean = append(clean, filepath.Clean(p))
}
if len(clean) == 0 {
return errors.New("no valid paths")
}
util.WriteFilePaths(clean) Defensive patterns
Strategy: validation
Validate before calling
func validClipboardPaths(paths []string) bool {
for _, p := range paths {
if p == "" || !utf8.ValidString(p) || strings.ContainsRune(p, 0) {
return false
}
}
return len(paths) > 0
} Try / catch
if err := util.WriteFilePaths(paths); err != nil {
if err.Error() == "no valid file paths to write (invalid UTF-8 or path)" {
// surface a clear 'invalid path' message to the user
}
} Prevention
- Resolve asset paths through model.GetAssetAbsPathInBox and utf8.ValidString them before writing.
- Reject empty strings and NUL-containing strings at the API boundary.
When it happens
Trigger: Calling WriteFilePaths on macOS with a slice whose strings are all invalid UTF-8, empty, or are not representable as file URLs (e.g. contain embedded NUL bytes or are malformed).
Common situations: Asset paths read from a non-UTF-8 filesystem encoding; a corrupt or empty path string passed from the asset API; a path containing a NUL byte after string processing.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to write file paths to pasteboard
- invalid rich clipboard asset count [%d]
- invalid rich clipboard asset index [%d]
- unsupported rich clipboard image extension [%s]
- writing file paths to clipboard is not supported on this pla
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/9d88e2de630b4dee.
Report an issue: GitHub.