{"record":{"id":"e39bc59199d83ad9","repo":"charmbracelet/crush","slug":"clipboard-is-empty-or-holds-an-unsupported-format","errorCode":null,"errorMessage":"clipboard is empty or holds an unsupported format","messagePattern":"clipboard is empty or holds an unsupported format","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"internal/clipboard/clipboard.go","lineNumber":24,"sourceCode":"import \"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\n// ErrEmpty when no matching data is present and ErrUnsupported on platforms\n// without clipboard support.\nfunc Read(f Format) ([]byte, error) {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/clipboard/clipboard.go#L6-L42","documentation":"clipboard.ErrEmpty is returned by clipboard.Read when the clipboard holds no data for the requested format. Unlike ErrUnsupported this is not a platform problem: the platform supports the clipboard but the content doesn't match what was asked for (e.g. asking for FormatImage when only text is present, or reading an empty clipboard).","triggerScenarios":"clipboard.Read(clipboard.FormatImage) when the clipboard contains text or nothing; clipboard.Read(clipboard.FormatText) on an empty clipboard; copying data in a format the reader doesn't map (e.g. non-PNG image data).","commonSituations":"User pressed paste-image but never actually copied an image; clipboard was cleared by another app between copy and read; copied image is in a format (JPEG, BMP) the reader treats as unsupported for FormatImage.","solutions":["Copy the intended content again immediately before reading, ensuring the format matches (PNG image for FormatImage, plain text for FormatText).","Handle ErrEmpty as an expected, non-fatal outcome: prompt the user that nothing usable was found.","If reading images, verify the source app actually places PNG data on the clipboard rather than a file path or other MIME type."],"exampleFix":"// before\ndata, err := clipboard.Read(clipboard.FormatImage)\nif err != nil {\n    return fmt.Errorf(\"clipboard read failed: %w\", err)\n}\n// after\ndata, err := clipboard.Read(clipboard.FormatImage)\nswitch {\ncase errors.Is(err, clipboard.ErrEmpty):\n    return nil // nothing copied; expected case\ncase err != nil:\n    return fmt.Errorf(\"clipboard read failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Nothing to pre-validate: clipboard content is external state.\n// Optionally check after read:\nif len(data) == 0 { /* treat as empty */ }","typeGuard":null,"tryCatchPattern":"data, err := clipboard.Read(clipboard.FormatImage)\nswitch {\ncase errors.Is(err, clipboard.ErrEmpty):\n    showHint(\"Nothing to paste — copy an image first\")\ncase err != nil:\n    return err\n}","preventionTips":["Copy the content immediately before reading to avoid clipboard races with other apps.","Match the requested Format to what was actually copied (text vs PNG image).","Treat ErrEmpty as an expected user-facing state, not a bug."],"tags":["go","clipboard","empty-content"],"backgroundTag":"clipboard-empty","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}