diesel-rs/diesel · error
DIESEL_MAX_COLUMN_COUNT is a number that fits into a u16
Error message
DIESEL_MAX_COLUMN_COUNT is a number that fits into a u16
What it means
This is a compile-time const-evaluation panic in diesel's table macro support. When the `custom-count-column-tables` feature is enabled, diesel reads the `DIESEL_MAX_COLUMN_COUNT` environment variable at compile time and parses it as a u16; if the value is missing or not a decimal number that fits in a u16, the const block panics and the build fails. It exists to validate the max-column-count configuration the table! macro relies on.
Solutions
- Set DIESEL_MAX_COLUMN_COUNT to a decimal integer between 0 and 65535 in the build environment (e.g. DIESEL_MAX_COLUMN_COUNT=64 cargo build).
- Check .cargo/config.toml [env] sections and CI matrices so every build profile that enables custom-count-column-tables exports the variable.
- If you don't actually need custom column counts, disable the `custom-count-column-tables` feature so the const block isn't compiled.
- Confirm the value contains only ASCII digits with no sign, spaces, or thousands separators.
Example fix
// before (build env) DIESEL_MAX_COLUMN_COUNT=100000 cargo build // exceeds u16::MAX -> compile-time panic // after DIESEL_MAX_COLUMN_COUNT=65535 cargo build
Defensive patterns
Strategy: validation
Validate before calling
// shell, before building
n="${DIESEL_MAX_COLUMN_COUNT}"
if ! [[ "$n" =~ ^[0-9]+$ ]] || [ "$n" -gt 65535 ]; then echo "DIESEL_MAX_COLUMN_COUNT must be a u16"; exit 1; fi Type guard
fn is_valid_max_column_count(v: &str) -> bool { v.parse::<u16>().is_ok() } Prevention
- Always set DIESEL_MAX_COLUMN_COUNT in .cargo/config.toml [env] alongside enabling custom-count-column-tables.
- Keep the value <= 65535; document the u16 constraint in your build docs.
- CI-lint the env value with a parse::<u16> check before compiling.
When it happens
Trigger: Compiling a crate with feature `custom-count-column-tables` enabled while the `DIESEL_MAX_COLUMN_COUNT` env var at build time is absent, non-numeric, negative, or greater than 65535, so `u16::from_str_radix` fails and the const block panics.
Common situations: Developers raising the column limit set DIESEL_MAX_COLUMN_COUNT to a value like 100000 (> u16::MAX), typo it (e.g. "32x"), or set it in .cargo/config.toml / CI for one build profile but not another. Upgrading diesel and newly enabling the feature without setting the env var also triggers it.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- Using window functions in WHERE clauses is not supported
- references are not supported in `Queryable` types consider…
- invalid variadic argument count: not enough function…
- Failed to create embedded migrations instance
- Unable to perform MySQL global initialization
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/bf71a3af719f0f48.
Report an issue: GitHub.
Appendix: source
Thrown at diesel/src/internal/table_macro.rs:48
#[doc(hidden)]
pub use crate::query_source::private::{Pick, PlainQuerySource, Sealed};
#[doc(hidden)]
pub mod ops {
#[doc(hidden)]
pub use crate::expression::ops::numeric::*;
}
#[doc(hidden)]
pub use crate::expand_mysql_like;
#[doc(hidden)]
pub use crate::expand_pg;
#[doc(hidden)]
#[cfg(feature = "custom-count-column-tables")]
pub const MAX_COLUMN_COUNT: u16 = {
let number = env!("DIESEL_MAX_COLUMN_COUNT");
let Ok(n) = u16::from_str_radix(number, 10) else {
panic!("DIESEL_MAX_COLUMN_COUNT is a number that fits into a u16");
};
n
};
#[doc(hidden)]
#[cfg(all(
not(feature = "custom-count-column-tables"),
feature = "128-column-tables"
))]
pub const MAX_COLUMN_COUNT: u16 = 128;
#[doc(hidden)]
#[cfg(all(
not(feature = "custom-count-column-tables"),
not(feature = "128-column-tables"),
feature = "64-column-tables"
))]
pub const MAX_COLUMN_COUNT: u16 = 64;
#[doc(hidden)]
#[cfg(all(View on GitHub (pinned to 6fa6ed01b2)