{"record":{"id":"c8b9ecf9aaaf7abf","repo":"diesel-rs/diesel","slug":"expected-to-be-set-as-environment-variable","errorCode":null,"errorMessage":"Expected `{}` to be set as environment variable","messagePattern":"Expected `(.+?)` to be set as environment variable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diesel_derives/src/diesel_for_each_tuple.rs","lineNumber":71,"sourceCode":"impl syn::parse::Parse for ForEachTupleInput {\n    fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {\n        let inner = input.parse()?;\n        input.parse::<syn::Token![,]>()?;\n        let max_size = if input.peek(syn::Ident) {\n            let macro_ident = input.parse::<syn::Ident>()?;\n            if macro_ident != \"env\" {\n                return Err(syn::Error::new(\n                    macro_ident.span(),\n                    \"only the `env!` macro is expected here\",\n                ));\n            }\n            let _bang = input.parse::<syn::Token![!]>()?;\n            let name;\n            syn::parenthesized!(name in input);\n            let s = name.parse::<syn::LitStr>()?;\n            std::env::var(s.value())\n                .map_err(|_| {\n                    syn::Error::new(\n                        s.span(),\n                        format!(\"Expected `{}` to be set as environment variable\", s.value()),\n                    )\n                })?\n                .parse::<u16>()\n                .map_err(|_| {\n                    syn::Error::new(\n                        s.span(),\n                        format!(\"Expected `{}` to be a u16 integer value\", s.value()),\n                    )\n                })?\n        } else {\n            input.parse::<syn::LitInt>()?.base10_parse()?\n        };\n        Ok(Self { inner, max_size })\n    }\n}\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/diesel_for_each_tuple.rs#L53-L89","documentation":"When `diesel_for_each_tuple!` receives `env!(VAR)` as the max tuple size, the proc macro reads the environment variable at compile time. If `std::env::var` fails (unset or non-UTF-8), the macro errors with this message naming the variable.","triggerScenarios":"`diesel_for_each_tuple!(table, env!(MAX_SIZE));` compiled without `MAX_SIZE` set in the build environment.","commonSituations":"CI environments missing a variable set locally; running `cargo build` outside a Makefile/setup script that exports the variable; misremembering the variable name (cargo env vars are not automatically inherited in all contexts).","solutions":["Set the environment variable before compiling (e.g. `export MAX_TUPLE_SIZE=32` or via a cargo config/`.env`-loading build script).","Replace `env!(VAR)` with a literal integer to remove the build-time dependency.","Fix a misspelled variable name in the `env!` call."],"exampleFix":"// before\ndiesel_for_each_tuple!(my_table, env!(MAX_TUPLE_SIZE));\n\n// after\ndiesel_for_each_tuple!(my_table, 32);","handlingStrategy":"validation","validationCode":"// Shell check before building\n# test -n \"$MAX_TUPLE_SIZE\" || { echo \"MAX_TUPLE_SIZE must be set\"; exit 1; }\n# or in a script:\nif [ -z \"${MAX_TUPLE_SIZE:-}\" ]; then echo \"Set MAX_TUPLE_SIZE, e.g. export MAX_TUPLE_SIZE=32\"; exit 1; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export required variables in CI config and local setup scripts","Document build-time env vars in README/CONTRIBUTING","Prefer a literal argument in the macro to avoid env dependence entirely"],"tags":["diesel","proc-macro","rust","environment-variable","build-time"],"backgroundTag":"missing-env-var","analyzedSha":"6fa6ed01b24b24248ab2a611698d0a7c6a2e9120","analyzedAt":"2026-09-07T01:50:13.074Z","contentChangedAt":"2026-09-07T01:50:13.074Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}