From 5ed62dbf76c899e0356ea4ae207a16ca747f7772 Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 14 Aug 2020 12:16:48 +0200 Subject: [PATCH 1/2] fix unwrap bug --- meilisearch-core/src/bucket_sort.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch-core/src/bucket_sort.rs b/meilisearch-core/src/bucket_sort.rs index b304e91c2..81b8f2f86 100644 --- a/meilisearch-core/src/bucket_sort.rs +++ b/meilisearch-core/src/bucket_sort.rs @@ -370,12 +370,12 @@ where let mut documents = Vec::with_capacity(range.len()); for raw_document in raw_documents.into_iter().skip(distinct_raw_offset) { let filter_accepted = match &filter { - Some(_) => filter_map.remove(&raw_document.id).unwrap(), + Some(_) => filter_map.remove(&raw_document.id).unwrap_or_default(), None => true, }; if filter_accepted { - let key = key_cache.remove(&raw_document.id).unwrap(); + let key = key_cache.remove(&raw_document.id).unwrap_or_default(); let distinct_accepted = match key { Some(key) => seen.register(key), None => seen.register_without_key(), From 2a79dc9ded084d6d5436ca0f12714c43eb614339 Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 17 Aug 2020 16:32:40 +0200 Subject: [PATCH 2/2] log error on unwrap error --- meilisearch-core/src/bucket_sort.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/meilisearch-core/src/bucket_sort.rs b/meilisearch-core/src/bucket_sort.rs index 81b8f2f86..f0fc71bd0 100644 --- a/meilisearch-core/src/bucket_sort.rs +++ b/meilisearch-core/src/bucket_sort.rs @@ -9,7 +9,7 @@ use std::time::Instant; use std::fmt; use compact_arena::{SmallArena, Idx32, mk_arena}; -use log::debug; +use log::{debug, error}; use sdset::{Set, SetBuf, exponential_search, SetOperation, Counter, duo::OpBuilder}; use slice_group_by::{GroupBy, GroupByMut}; @@ -370,12 +370,18 @@ where let mut documents = Vec::with_capacity(range.len()); for raw_document in raw_documents.into_iter().skip(distinct_raw_offset) { let filter_accepted = match &filter { - Some(_) => filter_map.remove(&raw_document.id).unwrap_or_default(), + Some(_) => filter_map.remove(&raw_document.id).unwrap_or_else(|| { + error!("error during filtering: expected value for document id {}", &raw_document.id.0); + Default::default() + }), None => true, }; if filter_accepted { - let key = key_cache.remove(&raw_document.id).unwrap_or_default(); + let key = key_cache.remove(&raw_document.id).unwrap_or_else(|| { + error!("error during distinct: expected value for document id {}", &raw_document.id.0); + Default::default() + }); let distinct_accepted = match key { Some(key) => seen.register(key), None => seen.register_without_key(),