{"record":{"id":"64cc291e0f7155ef","repo":"quickwit-oss/tantivy","slug":"this-implementation-always-produces-a-score","errorCode":null,"errorMessage":"This implementation always produces a score.","messagePattern":"This implementation always produces a score\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/collector/sort_key/sort_by_erased_type.rs","lineNumber":73,"sourceCode":"\n    fn convert_segment_sort_key(&self, sort_key: Option<u64>) -> OwnedValue {\n        let val = self.inner.convert_segment_sort_key(sort_key);\n        (self.converter)(val)\n    }\n}\n\nstruct ScoreSegmentSortKeyComputer {\n    segment_computer: SortBySimilarityScore,\n}\n\nimpl ErasedSegmentSortKeyComputer for ScoreSegmentSortKeyComputer {\n    fn segment_sort_key(&mut self, doc: DocId, score: Score) -> Option<u64> {\n        let score_value: f64 = self.segment_computer.segment_sort_key(doc, score).into();\n        Some(score_value.to_u64())\n    }\n\n    fn convert_segment_sort_key(&self, sort_key: Option<u64>) -> OwnedValue {\n        let score_value: u64 = sort_key.expect(\"This implementation always produces a score.\");\n        OwnedValue::F64(f64::from_u64(score_value))\n    }\n}\n\nimpl SortKeyComputer for SortByErasedType {\n    type SortKey = OwnedValue;\n    type Child = ErasedColumnSegmentSortKeyComputer;\n    type Comparator = NaturalComparator;\n\n    fn requires_scoring(&self) -> bool {\n        matches!(self, Self::Score)\n    }\n\n    fn segment_sort_key_computer(\n        &self,\n        segment_reader: &crate::SegmentReader,\n    ) -> crate::Result<Self::Child> {\n        let inner: Box<dyn ErasedSegmentSortKeyComputer> = match self {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/collector/sort_key/sort_by_erased_type.rs#L55-L91","documentation":"Fires in ScoreSegmentSortKeyComputer::convert_segment_sort_key, which converts a u64 sort key back to f64 for score-based sorting. Its counterpart segment_sort_key always returns Some(score encoded as u64), never None, so the Option unwrap is expected to be infallible; a None here means a sort key produced by a different computer (e.g. a field-based computer where missing values yield None) was fed to the score converter, breaking the pairing between key producer and converter.","triggerScenarios":"Thrown at src/collector/sort_key/sort_by_erased_type.rs:73 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the erased computer used to produce keys is the same ScoreSegmentSortKeyComputer used to convert them","Check that segment/collector wiring keeps producer and converter paired per sort specification","If None is a legitimate state, handle missing scores explicitly instead of panicking"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b5d8deb80c26924e6b007a5b1a7630f35ca64de4","analyzedAt":"2026-09-05T13:20:51.521Z","contentChangedAt":"2026-09-05T13:20:51.521Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}