{"record":{"id":"e48d8787820b05d7","repo":"sipeed/picoclaw","slug":"token-cannot-be-empty","errorCode":null,"errorMessage":"token cannot be empty","messagePattern":"token cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/auth/token.go","lineNumber":24,"sourceCode":"\t\"io\"\n\t\"strings\"\n)\n\nfunc LoginPasteToken(provider string, r io.Reader) (*AuthCredential, error) {\n\tfmt.Printf(\"Paste your API key or session token from %s:\\n\", providerDisplayName(provider))\n\tfmt.Print(\"> \")\n\n\tscanner := bufio.NewScanner(r)\n\tif !scanner.Scan() {\n\t\tif err := scanner.Err(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading token: %w\", err)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"no input received\")\n\t}\n\n\ttoken := strings.TrimSpace(scanner.Text())\n\tif token == \"\" {\n\t\treturn nil, fmt.Errorf(\"token cannot be empty\")\n\t}\n\n\treturn &AuthCredential{\n\t\tAccessToken: token,\n\t\tProvider:    provider,\n\t\tAuthMethod:  \"token\",\n\t}, nil\n}\n\nfunc LoginSetupToken(r io.Reader) (*AuthCredential, error) {\n\tfmt.Println(\"Paste your setup token from `claude setup-token`:\")\n\tfmt.Print(\"> \")\n\n\tscanner := bufio.NewScanner(r)\n\tif !scanner.Scan() {\n\t\tif err := scanner.Err(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading token: %w\", err)\n\t\t}","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/auth/token.go#L6-L42","documentation":"LoginPasteToken (pkg/auth/token.go:24) received a line but it was empty after TrimSpace — the user pressed Enter on a blank line or pasted only whitespace. The library rejects it because an empty AccessToken would produce a useless credential.","triggerScenarios":"At the 'Paste your API key or session token' prompt: pressing Enter immediately, pasting spaces/newlines only, or piping a whitespace-only string as the reader input.","commonSituations":"User unsure what to paste and pressing Enter to 'skip'; clipboard containing whitespace or a failed copy; scripted input accidentally passing ' ' or a blank variable; shell history expansion producing an empty line.","solutions":["Paste the actual key/token and press Enter — the prompt expects one non-blank line","If scripting, verify the variable is non-empty before wiring it: strings.NewReader(strings.TrimSpace(token))","Trim the clipboard content manually if it may contain leading/trailing whitespace (the function already trims, so pure whitespace means the clipboard itself was blank)","Check for trailing newlines breaking a pasted multiline value — only the first line is read"],"exampleFix":"// before\ncred, err := auth.LoginPasteToken(provider, os.Stdin)\n\n// after (guard before prompting in scripted use)\ntoken := strings.TrimSpace(os.Getenv(\"MY_TOKEN\"))\nif token == \"\" {\n\treturn fmt.Errorf(\"MY_TOKEN is empty; set it before login\")\n}\ncred, err := auth.LoginPasteToken(provider, strings.NewReader(token))","handlingStrategy":"validation","validationCode":"// Normalize and reject blank input before it reaches the prompt logic\nraw := strings.TrimSpace(suppliedToken)\nif raw == \"\" {\n\treturn fmt.Errorf(\"token value is empty; copy the key before pasting\")\n}\ncred, err := auth.LoginPasteToken(provider, strings.NewReader(raw))","typeGuard":"func isEmptyTokenError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"token cannot be empty\")\n}","tryCatchPattern":"cred, err := auth.LoginPasteToken(provider, r)\nif err != nil && isEmptyTokenError(err) {\n\t// harmless user slip: re-prompt instead of failing\n\tcred, err = auth.LoginPasteToken(provider, r)\n}","preventionTips":["Trim clipboard content before pasting; verify the copy actually captured the key","Re-prompt on empty input rather than aborting the login flow","Validate scripted tokens are non-empty before wiring them to the reader","Remember only the first line is read — multi-line secrets need different handling"],"tags":["input","validation","token","cli","go"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}