BigPizzaV3/CodexPlusPlus · error
供应商名称为空
Error message
供应商名称为空
What it means
This error is thrown by `normalize_request` in provider_import.rs when importing a provider whose `name` field is empty or whitespace-only after trimming. The library requires every imported provider to have a non-empty display name because the name identifies the provider entry in stored profiles and generated config. It is a fail-fast validation guard at the start of the import pipeline.
Solutions
- Set a non-empty `name` on the ProviderImportRequest before calling import_provider_with_store.
- If the name comes from user input, trim it and show a form-level error when it is blank.
- If importing from JSON, validate the name field exists and is non-blank before deserializing into the request.
Example fix
// before
let req = ProviderImportRequest { name: "".into(), base_url, api_key, ..Default::default() };
// after
let req = ProviderImportRequest { name: "My Relay".into(), base_url, api_key, ..Default::default() }; Defensive patterns
Strategy: validation
Validate before calling
let name = request.name.trim();
if name.is_empty() {
return Err(anyhow::anyhow!("供应商名称不能为空"));
}
request.name = name.to_string(); Type guard
fn has_name(req: &ProviderImportRequest) -> bool { !req.name.trim().is_empty() } Try / catch
match import_provider_with_store(&store, request) {
Ok(profile) => println!("imported {}", profile.name),
Err(e) if e.to_string().contains("供应商名称为空") => eprintln!("请填写供应商名称"),
Err(e) => return Err(e),
} Prevention
- Bind the import button to a form validation requiring a non-empty trimmed name.
- Never construct ProviderImportRequest with Default::default() for name in code paths.
- Validate JSON/import sources for the name field before deserialization.
When it happens
Trigger: Calling `import_provider_with_store` with a `ProviderImportRequest` whose `name` is `""` or only whitespace (e.g. `" "`), which normalize_request trims to empty before this bail fires at provider_import.rs:225.
Common situations: A UI or CLI form submitted without filling the provider name field; programmatic import building the request struct manually and forgetting `name`; deserializing a saved/import JSON where the name key was missing or blank.
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/32c177ff42450f60.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/provider_import.rs:225
vlm_api_key: String::new(),
vlm_model: String::new(),
vlm_base_url: String::new(),
user_agent: String::new(),
sub2api_enabled: false,
sub2api_multiplier: String::new(),
model_routes: Vec::new(),
standard_openai_protocol: false,
}
}
fn normalize_request(mut request: ProviderImportRequest) -> anyhow::Result<ProviderImportRequest> {
request.name = request.name.trim().to_string();
request.base_url = request.base_url.trim().trim_end_matches('/').to_string();
request.api_key = request.api_key.trim().to_string();
request.wire_api = request.wire_api.trim().to_ascii_lowercase();
request.relay_mode = request.relay_mode.trim().to_ascii_lowercase();
if request.name.is_empty() {
anyhow::bail!("供应商名称为空");
}
if request.base_url.is_empty() {
anyhow::bail!("Base URL 为空");
}
if request.api_key.is_empty() {
anyhow::bail!("API Key 为空");
}
request.config_contents = build_config_toml(
&request.base_url,
&request.api_key,
relay_protocol(&request.wire_api),
);
request.auth_contents = build_auth_json(&request.api_key);
Ok(request)
}
fn relay_protocol(value: &str) -> RelayProtocol {
match value.trim().to_ascii_lowercase().as_str() {View on GitHub (pinned to b1ed92e5e4)