influxdata/influxdb · error · Error::Conversion

{}

Error message

{}

What it means

This is the sole variant of `iox_query_params::Error`, representing a data conversion failure when building or parsing statement parameters. The library throws it when a parameter value cannot be converted into the expected internal representation; the human-readable detail is carried in the `msg` String field, so the message text is fully dynamic (rendered via `#[error("{}", msg)]`).

Solutions

  1. Read the `msg` payload — it contains the exact conversion failure description; fix the offending parameter value or type.
  2. Ensure parameter values match the expected types before calling `params!` (cast/parse explicitly with `serde_json::Value` helpers).
  3. Match on `iox_query_params::Error::Conversion { msg }` at the call site to surface `msg` to the user instead of a generic 500.

Example fix

// before
let p = params!["value" => user_input]; // may fail conversion
// after
let typed: i64 = user_input.parse().map_err(|e| Error::Conversion { msg: e.to_string() })?;
let p = params!["value" => typed];
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_param_ok(v: &serde_json::Value) -> Result<(), iox_query_params::Error> {
    if !v.is_string() && !v.is_i64() && !v.is_f64() && !v.is_boolean() {
        return Err(iox_query_params::Error::Conversion { msg: format!("unsupported param value: {:?}", v) });
    }
    Ok(())
}

Type guard

fn is_scalar(v: &serde_json::Value) -> bool {
    matches!(v, serde_json::Value::String(_) | serde_json::Value::Number(_) | serde_json::Value::Bool(_))
}

Try / catch

match build_params(user_input) {
    Ok(p) => run(p),
    Err(iox_query_params::Error::Conversion { msg }) => eprintln!("bad parameter: {msg}"),
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Constructing a `StatementParams` via the `params!` helper or the `Conversion { msg }` variant directly whenever a supplied parameter value fails type/value conversion (e.g. a value that cannot be coerced to the expected column/parameter type).

Common situations: Passing wrong-typed bind values to InfluxDB IOx query parameters, switching parameter APIs between versions and sending strings where numbers are expected, or wrapping lower-level conversion errors from value parsing into this enum.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/f6ac1bd174949b7b. Report an issue: GitHub.

Appendix: source

Thrown at core/iox_query_params/src/params.rs:36

use datafusion::common::metadata::ScalarAndMetadata;
use datafusion::scalar::ScalarValue;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::warn;

// remap protobuf types for convenience
mod proto {
    pub(super) use generated_types::influxdata::iox::querier::v1::{
        QueryParam,
        query_param::{NullValue, Value},
    };
}

#[derive(Debug, Error)]
/// Parameter errors
pub enum Error {
    /// Data conversion error
    #[error("{}", msg)]
    Conversion { msg: String },
}

/// A helper macro to construct a `StatementParams` collection.
/// ```
/// use iox_query_params::{params, StatementParams};
/// let my_params: StatementParams = params!(
///     "key1" => true,
///     "key2" => "string value",
///     "key3" => 1234,
///     "key4" => 3.14
/// );
/// assert_eq!(my_params.len(), 4);
/// ```
#[macro_export]
macro_rules! params {
    () => (
        $crate::StatementParams::new()

View on GitHub (pinned to 06200ef96b)