{"record":{"id":"0c67b07286e81092","repo":"charmbracelet/crush","slug":"clipboard-operations-are-not-supported-on-this-pla","errorCode":null,"errorMessage":"clipboard operations are not supported on this platform","messagePattern":"clipboard operations are not supported on this platform","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"internal/clipboard/clipboard.go","lineNumber":21,"sourceCode":"// requiring CGO or platform-specific dependencies.\npackage clipboard\n\nimport \"errors\"\n\n// Format identifies the kind of data to read from the clipboard.\ntype Format int\n\nconst (\n\t// FormatText is plain UTF-8 text.\n\tFormatText Format = iota\n\t// FormatImage is binary image data (PNG).\n\tFormatImage\n)\n\nvar (\n\t// ErrUnsupported is returned when clipboard access is not available on\n\t// the current platform.\n\tErrUnsupported = errors.New(\"clipboard operations are not supported on this platform\")\n\t// ErrEmpty is returned when the clipboard holds no data for the\n\t// requested format.\n\tErrEmpty = errors.New(\"clipboard is empty or holds an unsupported format\")\n)\n\n// Init initializes the clipboard subsystem. On unsupported platforms it\n// returns ErrUnsupported but is otherwise safe to call.\nfunc Init() error {\n\treturn initClipboard()\n}\n\n// WriteText writes plain text to the system clipboard. On unsupported\n// platforms it is a no-op.\nfunc WriteText(text string) {\n\twriteText(text)\n}\n\n// Read returns the clipboard contents for the given format. It returns","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/clipboard/clipboard.go#L3-L39","documentation":"clipboard.ErrUnsupported is returned when clipboard access is unavailable on the current platform. The clipboard package uses build tags: fully supported platforms get real implementations, while platforms without support (Android, iOS, or builds without CGO) compile in stub initClipboard/read that return this sentinel. Init is safe to call and simply reports ErrUnsupported instead of panicking.","triggerScenarios":"Calling clipboard.Init() or clipboard.Read(FormatText|FormatImage) on a platform compiled without clipboard support (the clipboard_not_supported.go build-tag variant); any write is a silent no-op on those platforms.","commonSituations":"Running crush on Android/iOS (e.g. via Termux-like environments), cross-compiling with CGO_ENABLED=0 for a target whose clipboard backend requires CGO, or running in minimal containers/SSH sessions without a clipboard service.","solutions":["Guard clipboard usage with errors.Is(err, clipboard.ErrUnsupported) and degrade gracefully (disable paste-image features).","Rebuild for the target platform with CGO enabled and the platform clipboard dependencies installed (e.g. xclip/xsel/wl-clipboard on Linux).","Call clipboard.Init() once at startup and record support status instead of relying on Read at use time."],"exampleFix":"// before\ndata, err := clipboard.Read(clipboard.FormatImage)\nif err != nil {\n    return err\n}\n// after\ndata, err := clipboard.Read(clipboard.FormatImage)\nif errors.Is(err, clipboard.ErrUnsupported) {\n    return nil // no clipboard on this platform; skip feature\n}\nif err != nil {\n    return err\n}","handlingStrategy":"fallback","validationCode":"// Probe clipboard support once at startup\nclipboardSupported := clipboard.Init() == nil","typeGuard":"func clipboardAvailable() bool { return !errors.Is(clipboard.Init(), clipboard.ErrUnsupported) }","tryCatchPattern":"data, err := clipboard.Read(clipboard.FormatText)\nif errors.Is(err, clipboard.ErrUnsupported) {\n    return nil // degrade: disable paste feature on this platform\n}\nif err != nil {\n    return err\n}","preventionTips":["Call Init() early and gate clipboard-dependent UI features on its result.","Build with the correct platform tags/CGO settings for targets that need clipboard support.","Treat ErrUnsupported as a permanent capability gap, never retry it."],"tags":["go","clipboard","platform","build-tags"],"backgroundTag":"clipboard-not-supported-on-platform","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}