{"record":{"id":"590b4c3e6f21a908","repo":"diesel-rs/diesel","slug":"expected-to-be-a-u16-integer-value","errorCode":null,"errorMessage":"Expected `{}` to be a u16 integer value","messagePattern":"Expected `(.+?)` to be a u16 integer value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diesel_derives/src/diesel_for_each_tuple.rs","lineNumber":78,"sourceCode":"                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":60,"sourceCodeEnd":89,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/diesel_for_each_tuple.rs#L60-L89","documentation":"After reading the environment variable in `diesel_for_each_tuple!`, the macro parses its value as a `u16`. If the string cannot be parsed as a u16 (e.g. non-numeric, negative, or too large), the macro emits this compile error.","triggerScenarios":"`env!(VAR)` where the variable contains something like `\"three\"`, `\"-1\"`, `\"70000\"`, or has stray whitespace.","commonSituations":"Copy-pasting a value with a trailing space or newline; exporting a string with units (`\"16 tuples\"`); a number exceeding u16 range for huge tuple sizes.","solutions":["Set the variable to a plain decimal integer within 0–65535 (e.g. `export MAX_TUPLE_SIZE=32`).","Trim surrounding whitespace/quotes from the exported value.","Use a literal integer argument in the macro instead of `env!`."],"exampleFix":"// before (shell)\nexport MAX_TUPLE_SIZE=\"32 tuples\"\n\n// after (shell)\nexport MAX_TUPLE_SIZE=32","handlingStrategy":"validation","validationCode":"// Validate before export / before build\npython3 -c 'import os,sys; v=os.environ.get(\"MAX_TUPLE_SIZE\",\"\"); n=int(v) if v.isdigit() else -1; sys.exit(0 if 0<=n<=65535 else 1)' || { echo \"MAX_TUPLE_SIZE must be a u16 integer\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export values unquoted and without units or whitespace","Keep tuple sizes <= 65535","Add a lint step in CI that validates numeric env vars"],"tags":["diesel","proc-macro","rust","environment-variable","integer-parsing"],"backgroundTag":"invalid-env-var-value","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"}