BigPizzaV3/CodexPlusPlus · error

Grok 模型别名不能为空

Error message

Grok 模型别名不能为空

What it means

validate_request performs input validation on SaveGrokConfigRequest before any file I/O in save_grok_config_at. Every requested model must have a non-empty alias after trimming; otherwise the library bails with "Grok 模型别名不能为空". Empty aliases cannot be represented as TOML table keys, so they are rejected up front.

Solutions

  1. Inspect each entry in request.models and find the one with an empty/whitespace alias.
  2. Set a non-empty, descriptive alias for that model entry.
  3. Drop the blank entry if it was added accidentally (e.g. an empty form row).
  4. Trim user input in the UI before constructing the request.
  5. Retry the save once all aliases are non-empty and unique.

Example fix

// before
SaveGrokConfigRequest { models: vec![ModelInput { alias: "  ".into(), .. }] }
// after
SaveGrokConfigRequest { models: vec![ModelInput { alias: "grok-fast".into(), .. }] }
Defensive patterns

Strategy: validation

Validate before calling

fn aliases_non_empty(models: &[ModelInput]) -> bool {
    models.iter().all(|m| !m.alias.trim().is_empty())
}

Type guard

fn has_alias(m: &ModelInput) -> Option<&str> {
    let a = m.alias.trim();
    if a.is_empty() { None } else { Some(a) }
}

Try / catch

match save_grok_config(req).await {
    Err(e) if e.to_string().contains("别名不能为空") => eprintln!("a model entry has an empty alias; fill or drop it"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling save_grok_config with a request.models element whose alias field is "" or whitespace-only (trim() yields empty), triggering the first check in validate_request.

Common situations: Frontend form submitted with a blank alias row; programmatic request building that left alias unset; pasting a model entry with a missing name field; whitespace-only input from copy-paste.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/b38389da14d3c3ac. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/grok_config.rs:277

            table.remove("api_key");
        } else if !input.api_key_update.trim().is_empty() {
            table.insert("api_key", toml_edit::value(input.api_key_update.trim()));
        }
        if models.contains_key(alias) {
            bail!("Grok 模型别名与未管理配置冲突:{alias}");
        }
        models.insert(alias, item);
    }
    Ok(())
}

fn validate_request(request: &SaveGrokConfigRequest) -> anyhow::Result<()> {
    let mut aliases = HashSet::new();
    let mut sources = HashSet::new();
    for input in &request.models {
        let alias = input.alias.trim();
        if alias.is_empty() {
            bail!("Grok 模型别名不能为空");
        }
        if alias.chars().any(char::is_control) {
            bail!("Grok 模型别名不能包含控制字符");
        }
        if !aliases.insert(alias.to_string()) {
            bail!("Grok 模型别名重复:{alias}");
        }
        let source = input.source_alias.trim();
        if !source.is_empty() && !sources.insert(source.to_string()) {
            bail!("Grok 模型来源别名重复:{source}");
        }
        if !matches!(
            input.api_backend.trim(),
            "responses" | "chat_completions" | "messages"
        ) {
            bail!("Grok 模型 {alias} 的 API 协议无效");
        }
        if input.context_window == Some(0) {

View on GitHub (pinned to b1ed92e5e4)