{"record":{"id":"fde4bd50fd467634","repo":"pola-rs/polars","slug":"offset-length-overflowed","errorCode":null,"errorMessage":"offset + length overflowed","messagePattern":"offset \\+ length overflowed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/array/mod.rs","lineNumber":466,"sourceCode":"        let f = |x: &$ty| Box::new(x.clone());\n        general_dyn!($array, $ty, f)\n    }};\n}\n\n// macro implementing `sliced` and `sliced_unchecked`\nmacro_rules! impl_sliced {\n    () => {\n        /// Returns this array sliced.\n        /// # Implementation\n        /// This function is `O(1)`.\n        /// # Panics\n        /// iff `offset + length > self.len()`.\n        #[inline]\n        #[must_use]\n        pub fn sliced(self, offset: usize, length: usize) -> Self {\n            let total = offset\n                .checked_add(length)\n                .expect(\"offset + length overflowed\");\n            assert!(\n                total <= self.len(),\n                \"the offset of the new Buffer cannot exceed the existing length\"\n            );\n            unsafe { Self::sliced_unchecked(self, offset, length) }\n        }\n\n        /// Returns this array sliced.\n        /// # Implementation\n        /// This function is `O(1)`.\n        ///\n        /// # Safety\n        /// The caller must ensure that `offset + length <= self.len()`.\n        #[inline]\n        #[must_use]\n        pub unsafe fn sliced_unchecked(mut self, offset: usize, length: usize) -> Self {\n            Self::slice_unchecked(&mut self, offset, length);\n            self","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/crates/polars-arrow/src/array/mod.rs#L448-L484","documentation":"Compile-time panic from #[polars_expr] in pyo3-polars-derive (lib.rs:128). With two extra parameters after the input slice, the only accepted pair is (\"context\", \"kwargs\"); any other combination of names panics with \"didn't expect arguments {a}, {b}\" showing both offending names. The names are matched exactly — misspellings like ctx, contex, kw_args, or unrelated names like options/extra all land here.","triggerScenarios":"fn f(inputs: &[Series], ctx: CallerContext, kwargs: MyKwargs) (ctx misspelled), fn f(inputs: &[Series], context: CallerContext, options: MyKwargs) (second name unrecognized), or fn f(inputs: &[Series], factor: f64, kwargs: MyKwargs) (a positional config parameter the macro does not support).","commonSituations":"Trying to pass extra configuration as an additional positional function parameter instead of through the kwargs struct; partial rename refactorings that fix one name but not the other; code review feedback that renamed parameters for clarity, silently breaking the macro's name-based dispatch.","solutions":["Rename both parameters to exactly context: CallerContext and kwargs: YourKwargsStruct, in that order","If one of the two is custom configuration, move it into the kwargs struct (a Deserialize type deserialized via the pickle protocol) instead of a separate positional parameter","Drop unneeded parameters so only the recognized ones remain","Re-run cargo check after each rename; the panic message names the exact identifiers it rejected"],"exampleFix":"// before — `ctx` and `options` are not recognized names\n#[polars_expr(output_type=String)]\nfn f(inputs: &[Series], ctx: CallerContext, options: MyKwargs) -> PolarsResult<Series> {\n    todo!()\n}\n\n// after\n#[polars_expr(output_type=String)]\nfn f(inputs: &[Series], context: CallerContext, kwargs: MyKwargs) -> PolarsResult<Series> {\n    todo!()\n}","handlingStrategy":"validation","validationCode":"# ci/check_polars_expr.py — run before cargo build\nimport re, sys, pathlib\npat = re.compile(r\"#\\[polars_expr\\([^)]*\\)\\]\\s*(?:pub\\s+)?fn\\s+\\w+\\(([^)]*)\\)\", re.S)\nfor f in pathlib.Path(\"src\").rglob(\"*.rs\"):\n    for m in pat.finditer(f.read_text()):\n        params = [p.strip() for p in m.group(1).split(\",\") if p.strip()]\n        if len(params) == 3:\n            names = [p.split(\":\")[0].strip() for p in params[1:]]\n            if names != [\"context\", \"kwargs\"]:\n                sys.exit(f\"{f}: trailing pair {names} must be exactly ['context', 'kwargs']\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Names are matched byte-exact: context not ctx/contex, kwargs not kw_args/args","Pass per-call options only through the kwargs struct, never as extra positional parameters","Read the panic text — it prints the exact identifiers it rejected, which pinpoints the typo"],"tags":["rust","proc-macro","polars","compile-time","parameter-names"],"backgroundTag":"proc-macro-panicked","analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}