{"record":{"id":"f1ba6d8384ee15ca","repo":"sipeed/picoclaw","slug":"reading-token-w","errorCode":null,"errorMessage":"reading token: %w","messagePattern":"reading token: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/auth/token.go","lineNumber":17,"sourceCode":"package auth\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\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`:\")","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/auth/token.go#L1-L35","documentation":"LoginPasteToken (pkg/auth/token.go:17) failed while reading the pasted token: bufio.Scanner reported a hard error. The wrapped error distinguishes causes — most commonly bufio.ErrBufferTooLong when a single line exceeds the 64 KiB default scanner buffer, or an I/O error on the provided reader (broken pipe, closed stdin).","triggerScenarios":"Calling LoginPasteToken with r = os.Stdin (or another reader) where the line exceeds bufio.MaxScanTokenSize (65536 bytes), the reader returns a read error, or the input stream errors before a newline.","commonSituations":"Pasting a very long session token/JWT chain (>64 KiB) into the interactive prompt; piping a file that dies mid-read; automation passing a closed pipe as the reader; terminal multiplexers mangling huge pastes.","solutions":["Check scanner.Err(): 'token too long' means the buffer limit — enlarge it with scanner.Buffer(buf, maxSize)","Keep tokens under 64 KiB or feed them via a file/pipe: LoginPasteToken(provider, strings.NewReader(token)) programmatically","If the reader is a pipe, verify the writer side stays open for the duration of the read","Test with a small known token first to separate size issues from stream issues"],"exampleFix":"// before\nscanner := bufio.NewScanner(r)\n\n// after (allow long tokens)\nscanner := bufio.NewScanner(r)\nscanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)","handlingStrategy":"validation","validationCode":"// Pre-size the reader path: read via a scanner with a large buffer yourself\nsc := bufio.NewScanner(r)\nsc.Buffer(make([]byte, 0, 64*1024), 1024*1024)\nif !sc.Scan() {\n\treturn fmt.Errorf(\"no token line available\")\n}\n// pass sc.Text() on, or pass a strings.NewReader to the library","typeGuard":"func isTokenReadError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"reading token\")\n}","tryCatchPattern":"cred, err := auth.LoginPasteToken(provider, r)\nif err != nil && isTokenReadError(err) {\n\tif errors.Is(err, bufio.ErrBufferTooLong) {\n\t\t// token exceeded 64 KiB scanner limit\n\t\treturn fmt.Errorf(\"token too long for interactive paste: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Pass programmatic tokens via strings.NewReader instead of stdin","Enlarge the scanner buffer if very long tokens are expected","Keep the writer side of pipes open during reads","Test the paste flow with real-length tokens, not short fixtures"],"tags":["input","stdin","bufio","token","go"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}