nikivdev/code · error · anyhow::Error

Token cannot be empty

Error message

Token cannot be empty

What it means

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.

Source

Thrown at src/env.rs:2413

    println!("  1. Go to {} and sign in", DEFAULT_API_URL);
    println!("  2. Go to Settings → API Tokens");
    println!("  3. Create a new token");
    println!();

    let api_url = prompt_line_default("API base URL", Some(DEFAULT_API_URL))?;
    if let Some(api_url) = api_url {
        auth.api_url = Some(api_url);
    }

    print!("Enter your API token: ");
    io::stdout().flush()?;

    let mut token = String::new();
    io::stdin().read_line(&mut token)?;
    let token = token.trim().to_string();

    if token.is_empty() {
        bail!("Token cannot be empty");
    }

    if !token.starts_with("cloud_") && !token.starts_with("flow_") {
        println!(
            "Warning: Token doesn't start with 'cloud_' or 'flow_' - are you sure this is correct?"
        );
    }

    store_auth_token(&mut auth, token)?;
    save_auth_config(&auth)?;

    println!();
    if auth.token_source.as_deref() == Some("keychain") {
        println!("✓ Token saved to Keychain");
    } else {
        println!("✓ Token saved to {}", get_auth_config_path().display());
    }
    println!();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Re-run `f env login` and paste the actual cloud_ or flow_ token.
  2. Copy the token from the cloud dashboard again and ensure the paste succeeded before pressing Enter.
  3. For automation, ensure the piped input actually contains the token and a trailing newline.

Example fix

// before (non-interactive, fails)
echo "" | f env login
// after
echo "cloud_abcd1234..." | f env login
Defensive patterns

Strategy: validation

Validate before calling

// Validate the token string before piping into login:
let tok = env::var("FLOW_TOKEN")?;
if tok.trim().is_empty() {
    bail!("FLOW_TOKEN is empty; export a valid cloud_/flow_ token");
}
println!("{}", tok)

Prevention

When it happens

Trigger: Pressing Enter immediately at the token prompt; pasting nothing; piping empty input (e.g. `echo | f env login`) in a scripted login attempt.

Common situations: 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.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/bb79032c150f38a9. Report an issue: GitHub.