From f3d691667d47985347766f134b294a2a8354bbe2 Mon Sep 17 00:00:00 2001 From: Martin Tzvetanov Grigorov Date: Mon, 26 May 2025 13:39:15 +0300 Subject: [PATCH] Use a Regex in insta dynamic redaction to replace Uuids with [uuid] Signed-off-by: Martin Tzvetanov Grigorov --- crates/index-scheduler/src/error.rs | 13 +------------ crates/meili-snap/src/lib.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/index-scheduler/src/error.rs b/crates/index-scheduler/src/error.rs index cbedf827d..cb798b385 100644 --- a/crates/index-scheduler/src/error.rs +++ b/crates/index-scheduler/src/error.rs @@ -126,7 +126,7 @@ pub enum Error { #[error(transparent)] Heed(#[from] heed::Error), #[error("{}", match .index_uid { - Some(uid) if !uid.is_empty() => format!("Index `{}`: {error}", Error::index_name(uid)), + Some(uid) if !uid.is_empty() => format!("Index `{}`: {error}", uid), _ => format!("{error}") })] Milli { error: milli::Error, index_uid: Option }, @@ -177,17 +177,6 @@ pub enum Error { PlannedFailure, } -impl Error { - #[inline] - fn index_name(index_name: &str) -> &str { - if uuid::Uuid::parse_str(index_name).is_ok() { - "[uuid]" - } else { - index_name - } - } -} - #[derive(Debug, thiserror::Error)] #[error( "{disabled_action} requires enabling the `{feature}` experimental feature. See {issue_link}" diff --git a/crates/meili-snap/src/lib.rs b/crates/meili-snap/src/lib.rs index 30769c7c1..0f709b3de 100644 --- a/crates/meili-snap/src/lib.rs +++ b/crates/meili-snap/src/lib.rs @@ -55,6 +55,14 @@ pub fn default_snapshot_settings_for_test<'a>( } }); + settings.add_dynamic_redaction(".error.message", |content, _content_path| match &content { + Content::String(s) => { + let uuid_replaced = UUID_IN_MESSAGE_RE.replace_all(s, "$before[uuid]$after"); + Content::String(uuid_replaced.to_string()) + } + _ => content, + }); + let test_name = test_name.strip_suffix("::{{closure}}").unwrap_or(test_name); let test_name = test_name.rsplit("::").next().unwrap().to_owned();