{"record":{"id":"ffefb7f3dff30af5","repo":"micro-editor/micro","slug":"invalid-clipboard-method","errorCode":null,"errorMessage":"Invalid clipboard method","messagePattern":"Invalid clipboard method","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/clipboard/clipboard.go","lineNumber":136,"sourceCode":"\t\t\treturn string(b), e\n\t\tdefault:\n\t\t\treturn internal.read(r), nil\n\t\t}\n\tcase Internal:\n\t\treturn internal.read(r), nil\n\tcase Terminal:\n\t\tswitch r {\n\t\tcase ClipboardReg:\n\t\t\t// terminal paste works by sending an esc sequence to the\n\t\t\t// terminal to trigger a paste event\n\t\t\treturn terminal.read(\"clipboard\")\n\t\tcase PrimaryReg:\n\t\t\treturn terminal.read(\"primary\")\n\t\tdefault:\n\t\t\treturn internal.read(r), nil\n\t\t}\n\t}\n\treturn \"\", errors.New(\"Invalid clipboard method\")\n}\n\nfunc write(text string, r Register, m Method) error {\n\tswitch m {\n\tcase External:\n\t\tswitch r {\n\t\tcase ClipboardReg:\n\t\t\treturn clipboard.WriteAll(clipper.RegClipboard, []byte(text))\n\t\tcase PrimaryReg:\n\t\t\treturn clipboard.WriteAll(clipper.RegPrimary, []byte(text))\n\t\tdefault:\n\t\t\tinternal.write(text, r)\n\t\t}\n\tcase Internal:\n\t\tinternal.write(text, r)\n\tcase Terminal:\n\t\tswitch r {\n\t\tcase ClipboardReg:","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/micro-editor/micro/blob/1c8b82b32e408a5faf340039ed92d5266bea3293/internal/clipboard/clipboard.go#L118-L154","documentation":"Returned by clipboard.read(r, m) when the Method value passed to the switch is none of External, Internal, or Terminal. In practice CurrentMethod is only ever assigned those three constants, so this is a programming-error sentinel for callers who construct a Method directly (e.g. clipboard.Method(9)) or who add a new Method constant without extending read/write switches in internal/clipboard/clipboard.go.","triggerScenarios":"Calling the unexported read via a package refactor with an out-of-range Method, or clipboard.Initialize/SetMethod flow bypassed so CurrentMethod holds a zero-value-altered integer. Note SetMethod silently ignores unknown strings (keeps previous value), so a bad \"clipboard\" setting does NOT produce this error — only an invalid Method integer does.","commonSituations":"Library consumers embedding micro's clipboard package and passing a Method read from config as a raw int; developers adding a fourth clipboard backend (e.g. Wayland-native) and forgetting one switch statement.","solutions":["Pass only constants: clipboard.External, clipboard.Internal, or clipboard.Terminal.","If you added a new Method constant, add its case to both read() and write() switches in internal/clipboard/clipboard.go.","Set the method by name via clipboard.SetMethod(\"internal\"|\"external\"|\"terminal\") which can never produce an invalid value.","Guard with a range check (see validation) before calling Read/Write in wrapper code."],"exampleFix":"// before:\nm := clipboard.Method(cfgInt) // cfgInt == 7 -> falls through\n_, err := clipboard.Read(clipboard.ClipboardReg) // err: Invalid clipboard method\n\n// after:\nswitch cfgStr {\ncase \"external\", \"terminal\", \"internal\":\n    clipboard.SetMethod(cfgStr)\ndefault:\n    clipboard.SetMethod(\"internal\")\n}\n_, err := clipboard.Read(clipboard.ClipboardReg)","handlingStrategy":"validation","validationCode":"func validMethod(m clipboard.Method) bool {\n    return m == clipboard.External || m == clipboard.Internal || m == clipboard.Terminal\n}\n\nif !validMethod(m) { m = clipboard.Internal }","typeGuard":"func isValidMethod(m clipboard.Method) bool {\n    switch m {\n    case clipboard.External, clipboard.Internal, clipboard.Terminal:\n        return true\n    }\n    return false\n}","tryCatchPattern":"text, err := clipboard.Read(clipboard.ClipboardReg)\nif err != nil && err.Error() == \"Invalid clipboard method\" {\n    text, err = clipboard.Read /* after clipboard.SetMethod(\"internal\") */\n}","preventionTips":["Always obtain a Method via clipboard.SetMethod(name) with a whitelisted string, never by casting ints.","If you add a Method constant, grep the package switches in read()/write() and extend both.","Default unknown config values to \"internal\" before calling SetMethod."],"tags":["clipboard","enum","programming-error","switch"],"backgroundTag":null,"analyzedSha":"1c8b82b32e408a5faf340039ed92d5266bea3293","analyzedAt":"2026-08-15T20:01:45.134Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}