{"record":{"id":"bb79032c150f38a9","repo":"nikivdev/code","slug":"token-cannot-be-empty","errorCode":null,"errorMessage":"Token cannot be empty","messagePattern":"Token cannot be empty","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/env.rs","lineNumber":2413,"sourceCode":"    println!(\"  1. Go to {} and sign in\", DEFAULT_API_URL);\n    println!(\"  2. Go to Settings → API Tokens\");\n    println!(\"  3. Create a new token\");\n    println!();\n\n    let api_url = prompt_line_default(\"API base URL\", Some(DEFAULT_API_URL))?;\n    if let Some(api_url) = api_url {\n        auth.api_url = Some(api_url);\n    }\n\n    print!(\"Enter your API token: \");\n    io::stdout().flush()?;\n\n    let mut token = String::new();\n    io::stdin().read_line(&mut token)?;\n    let token = token.trim().to_string();\n\n    if token.is_empty() {\n        bail!(\"Token cannot be empty\");\n    }\n\n    if !token.starts_with(\"cloud_\") && !token.starts_with(\"flow_\") {\n        println!(\n            \"Warning: Token doesn't start with 'cloud_' or 'flow_' - are you sure this is correct?\"\n        );\n    }\n\n    store_auth_token(&mut auth, token)?;\n    save_auth_config(&auth)?;\n\n    println!();\n    if auth.token_source.as_deref() == Some(\"keychain\") {\n        println!(\"✓ Token saved to Keychain\");\n    } else {\n        println!(\"✓ Token saved to {}\", get_auth_config_path().display());\n    }\n    println!();","sourceCodeStart":2395,"sourceCodeEnd":2431,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/env.rs#L2395-L2431","documentation":"Raised during interactive `f env login` when the token the user types, after trimming, is an empty string. The CLI requires a non-empty token to store in the auth config, so it bails before any prefix validation or persistence. No API call is made and the login fails.","triggerScenarios":"Pressing Enter immediately at the token prompt; pasting nothing; piping empty input (e.g. `echo | f env login`) in a scripted login attempt.","commonSituations":"Terminal paste failure (clipboard empty); automating login with a script that feeds blank input; user believing the prompt was for confirmation rather than token entry.","solutions":["Re-run `f env login` and paste the actual cloud_ or flow_ token.","Copy the token from the cloud dashboard again and ensure the paste succeeded before pressing Enter.","For automation, ensure the piped input actually contains the token and a trailing newline."],"exampleFix":"// before (non-interactive, fails)\necho \"\" | f env login\n// after\necho \"cloud_abcd1234...\" | f env login","handlingStrategy":"validation","validationCode":"// Validate the token string before piping into login:\nlet tok = env::var(\"FLOW_TOKEN\")?;\nif tok.trim().is_empty() {\n    bail!(\"FLOW_TOKEN is empty; export a valid cloud_/flow_ token\");\n}\nprintln!(\"{}\", tok)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Paste the token and visually confirm non-empty input before pressing Enter.","For scripted login, assert the token variable is non-empty before piping.","Store the token in a secret manager rather than retyping it interactively."],"tags":["auth","validation","cli","empty-input"],"backgroundTag":"empty-token-input","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}