{"record":{"id":"7ca3b6dc28586ebf","repo":"siyuan-note/siyuan","slug":"writing-file-paths-to-clipboard-is-not-supported-o","errorCode":null,"errorMessage":"writing file paths to clipboard is not supported on this platform","messagePattern":"writing file paths to clipboard is not supported on this platform","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/util/clipboard.go","lineNumber":25,"sourceCode":"// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\n//go:build (!windows && !darwin) || ios\n\npackage util\n\nimport \"errors\"\n\n// 当前仅在 Windows、macOS 上实现，其他平台返回错误\nfunc WriteFilePaths(paths []string) error {\n\treturn errors.New(\"writing file paths to clipboard is not supported on this platform\")\n}\n","sourceCodeStart":7,"sourceCodeEnd":27,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/clipboard.go#L7-L27","documentation":"Returned by the WriteFilePaths stub selected when the build constraint (!windows && !darwin) || ios holds. SiYuan only implements file-path clipboard writing for Windows (CF_HDROP) and macOS (NSPasteboard); on Linux desktop, Android, and iOS the function is a compile-time stub that always errors. The error is a deliberate unsupported-platform sentinel, not a runtime fault.","triggerScenarios":"Calling util.WriteFilePaths (directly, or via the kernel API that copies an asset as a file, kernel/api/clipboard.go:90) in a build whose GOOS is neither windows nor darwin, or in an iOS (mobile) build.","commonSituations":"Running the Electron/desktop kernel on Linux and using the asset 'copy as file' menu; running the kernel in a Docker/headless Linux container; invoking the same clipboard API path from an Android or iOS gomobile build.","solutions":["Guard the call site with a runtime.GOOS check and skip 'copy as file' (or fall back to writing the path as plain text) on unsupported platforms.","If the feature is required, run on Windows or macOS where the real implementation is compiled in.","Add a platform implementation for the missing OS instead of calling the stub."],"exampleFix":"// before\nif err := util.WriteFilePaths([]string{absPath}); err != nil {\n    return err\n}\n\n// after\nif runtime.GOOS != \"windows\" && runtime.GOOS != \"darwin\" {\n    // fall back to plain-text path on the clipboard\n    return writeTextClipboard(absPath)\n}\nif err := util.WriteFilePaths([]string{absPath}); err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"func isWriteFilePathsSupported() bool {\n    switch runtime.GOOS {\n    case \"windows\", \"darwin\":\n        return runtime.GOOS != \"darwin\" || !isIOSSBuild // ios build sets darwin+ios tag\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate 'copy asset as file' UI on the supported platforms so the stub is never reached.","Provide a plain-text path fallback so the user still gets the path on Linux/mobile."],"tags":["clipboard","platform","build-tags","linux","ios"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}