openai/codex · error · ConstraintError
field `{field_name}` cannot be empty
Error message
field `{field_name}` cannot be empty What it means
ConstraintError::EmptyField (codex-rs/config/src/constraint.rs:22, built via ConstraintError::empty_field) is returned by a Constrained validator when a field that must be non-empty receives an empty string. field_name in the message identifies exactly which field failed.
Source
Thrown at codex-rs/config/src/constraint.rs:22
use crate::config_requirements::RequirementSource;
use thiserror::Error;
#[derive(Debug, Error, PartialEq, Eq)]
pub enum ConstraintError {
#[error(
"invalid value for `{field_name}`: `{candidate}` is not in the allowed set {allowed} (set by {requirement_source})"
)]
InvalidValue {
field_name: &'static str,
candidate: String,
allowed: String,
requirement_source: RequirementSource,
},
#[error("To use model `{model}`, you need to use auto review.")]
AutoReviewRequired { model: String },
#[error("field `{field_name}` cannot be empty")]
EmptyField { field_name: String },
#[error("invalid rules in requirements (set by {requirement_source}): {reason}")]
ExecPolicyParse {
requirement_source: RequirementSource,
reason: String,
},
#[error(
"invalid requirement for MCP server `{server_name}` (set by {requirement_source}): {reason}"
)]
McpServerRequirementParse {
server_name: String,
requirement_source: RequirementSource,
reason: String,
},
}
View on GitHub (pinned to 339751715c)
Solutions
- Give the field a non-empty value
- Remove the key entirely instead of setting it to an empty string
- If the value comes from an env var, default it or skip writing the key when the variable is empty
Example fix
# before name = "" # after name = "my-server"
Defensive patterns
Strategy: validation
Validate before calling
fn non_empty(field: &str) -> Result<&str, String> {
let t = field.trim();
if t.is_empty() {
Err("field cannot be empty".into())
} else {
Ok(t)
}
} Type guard
fn is_non_empty(s: &str) -> bool {
!s.trim().is_empty()
} Try / catch
match constrained.set(value) {
Err(ConstraintError::EmptyField { field_name }) => {
eprintln!("{field_name} must not be empty");
}
r => r?,
} Prevention
- Trim and reject empty inputs at the form or API boundary before they reach config
- Omit keys rather than writing them as empty strings in generated configs
- Unit-test config writers against empty env vars
When it happens
Trigger: Setting a constrained non-empty string field (a name or identifier in config or requirements) to an empty string via config.toml, an override, or an API set call; the validator does not trim, so empty and whitespace-only values fail.
Common situations: Template configs generated with empty placeholders (name = ""); env-var-driven overrides that expand to an empty string; scripts writing config keys unconditionally even when the source value is missing.
Related errors
- invalid value for `{field_name}`: `{candidate}` is not in th
- To use model `{model}`, you need to use auto review.
- invalid requirement for MCP server `{server_name}` (set by {
- failed to decrypt encrypted task id
- approval_policy = "untrusted" is no longer supported; remove
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/9b0bc7ceb72c1ea9.
Report an issue: GitHub.