t8y2/dbx · error

{key} is required

Error message

{key} is required

What it means

Validation error from `required_string`, a helper that extracts a mandatory string parameter from the JSON `params` object passed to `dispatch`/`dispatch_driver`. It fails when the key is absent, not a string (e.g. a number or null), or present but empty/whitespace-only. The message names the missing key so callers know which field to supply.

Source

Thrown at agents/drivers/tdengine/src/runtime.rs:381

        _ => bail!("unknown method: {method}"),
    }
}

fn decode<T: DeserializeOwned>(params: &Value) -> Result<T> {
    serde_json::from_value(params.clone()).with_context(|| "invalid TDengine agent request parameters")
}

fn serialize<T: serde::Serialize>(value: T) -> Result<Value> {
    serde_json::to_value(value).map_err(anyhow::Error::from)
}

fn required_string(params: &Value, key: &str) -> Result<String> {
    params
        .get(key)
        .and_then(Value::as_str)
        .map(str::to_string)
        .filter(|value| !value.trim().is_empty())
        .ok_or_else(|| anyhow!("{key} is required"))
}

fn optional_string(params: &Value, key: &str) -> String {
    params.get(key).and_then(Value::as_str).unwrap_or_default().to_string()
}

fn optional_usize(params: &Value, key: &str) -> Option<usize> {
    params.get(key).and_then(Value::as_u64).and_then(|value| usize::try_from(value).ok())
}

fn optional_u64(params: &Value, key: &str) -> Option<u64> {
    params.get(key).and_then(Value::as_u64)
}

fn string_array(params: &Value, key: &str) -> Result<Vec<String>> {
    params
        .get(key)
        .cloned()

View on GitHub (pinned to c0390bff16)

Solutions

  1. Add the named key to the params JSON object as a non-empty string.
  2. Check the key spelling against the driver's expected parameter names.
  3. Ensure the value's JSON type is a string, not a number, boolean, or null.
  4. Trim-or-default client-side inputs so empty user input is caught before dispatch.

Example fix

// before
let params = json!({"action": "query"});
// after
let params = json!({"action": "query", "sql": "SELECT 1"}); // required key supplied
Defensive patterns

Strategy: validation

Validate before calling

fn require_param(params: &serde_json::Value, key: &str) -> Result<&str, String> {
    params.get(key)
        .and_then(serde_json::Value::as_str)
        .map(|s| s.trim())
        .filter(|s| !s.is_empty())
        .ok_or_else(|| format!("{key} is required"))
}
// call before dispatch: require_param(&params, "sql")?;

Type guard

fn is_nonempty_str(v: &serde_json::Value) -> Option<&str> {
    v.as_str().filter(|s| !s.trim().is_empty())
}

Prevention

When it happens

Trigger: Calling dispatch/dispatch_driver without a required key in `params`; passing a JSON null, number, or object where a string is expected; passing `""` or `" "` which the `.filter(|v| !v.trim().is_empty())` rejects.

Common situations: Omitting fields like `id` or `sql` in hand-built JSON payloads; forgetting that whitespace-only values are rejected; sending the field with the wrong JSON type (unquoted or numeric); serializing optional fields as null.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/65e74174d00b3609. Report an issue: GitHub.