{"record":{"id":"bb5b6eeb3831f911","repo":"risingwavelabs/risingwave","slug":"must-have-at-least-one-element-in-offsets","errorCode":null,"errorMessage":"Must have at least one element in offsets","messagePattern":"Must have at least one element in offsets","errorType":"error_code","errorClass":"ArrayError","httpStatus":null,"severity":"error","filePath":"src/common/src/array/list_array.rs","lineNumber":264,"sourceCode":"        &self.value\n    }\n\n    pub fn from_protobuf(array: &PbArray) -> ArrayResult<ArrayImpl> {\n        ensure!(\n            array.values.is_empty(),\n            \"Must have no buffer in a list array\"\n        );\n        debug_assert!(\n            (array.array_type == PbArrayType::List as i32)\n                || (array.array_type == PbArrayType::Map as i32),\n            \"invalid array type for list: {}\",\n            array.array_type\n        );\n        let bitmap: Bitmap = array.get_null_bitmap()?.into();\n        let array_data = array.get_list_array_data()?.to_owned();\n        let flatten_len = match array_data.offsets.last() {\n            Some(&n) => n as usize,\n            None => bail!(\"Must have at least one element in offsets\"),\n        };\n        let value = ArrayImpl::from_protobuf(array_data.value.as_ref().unwrap(), flatten_len)?;\n        let arr = ListArray {\n            bitmap,\n            offsets: array_data.offsets.into(),\n            value: Box::new(value),\n        };\n        Ok(arr.into())\n    }\n\n    /// Apply the function on the underlying elements.\n    /// e.g. `map_inner([[1,2,3],NULL,[4,5]], DOUBLE) = [[2,4,6],NULL,[8,10]]`\n    pub fn map_inner_sync<E, F>(self, f: F) -> std::result::Result<ListArray, E>\n    where\n        F: FnOnce(ArrayImpl) -> std::result::Result<ArrayImpl, E>,\n    {\n        let new_value = (f)(*self.value)?;\n","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/common/src/array/list_array.rs#L246-L282","documentation":"During `ListArray::from_protobuf`, the flattened length is derived from the last element of `array_data.offsets`. If `offsets` is empty there is no way to compute the cardinality of the nested value array, so decoding is rejected.","triggerScenarios":"Calling `ListArray::from_protobuf` on a PbArray whose `list_array_data.offsets` vector is empty — e.g. the serializer failed to write offsets or the payload was truncated/hand-built without them.","commonSituations":"Manually constructed protobuf in tests missing offsets; data corruption in transit/storage; a serializer bug after schema evolution that drops the offsets field.","solutions":["Ensure `ListArray::to_protobuf` (or equivalent) always writes at least one offsets entry (starting at 0).","Check that the source chunk is not truncated and `list_array_data` is fully populated.","Validate `array_data.offsets` is non-empty upstream and produce a clearer error.","Look for recent changes to list-array serialization that may have omitted offsets."],"exampleFix":"// before\nlet flatten_len = match array_data.offsets.last() {\n    Some(&n) => n as usize,\n    None => bail!(\"Must have at least one element in offsets\"),\n};\n// after (caller-side guard)\nensure!(!pb_array.get_list_array_data()?.offsets.is_empty(), \"list array payload missing offsets\");\nlet arr = ListArray::from_protobuf(&pb_array)?;","handlingStrategy":"validation","validationCode":"let data = pb_array.get_list_array_data()?;\nif data.offsets.is_empty() { return Err(\"list array offsets empty\".into()); }","typeGuard":"fn has_offsets(a: &PbArray) -> bool {\n    a.get_list_array_data().map(|d| !d.offsets.is_empty()).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Ensure serializers always emit at least the initial 0 offset","Checksum/verify protobuf payloads in transit","Round-trip test list arrays with empty and nested lists"],"tags":["rust","array","list","offsets","deserialization"],"backgroundTag":"empty-required-field","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}