From d908b626beabe5685e03131a4b6a14ace2533524 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 21 Jun 2026 20:50:26 +0200 Subject: pkgs/lf-make-map: Improve error message --- pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'pkgs/by-name/lf/lf-make-map/src/mapping') diff --git a/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs b/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs index d90eb963..6d88d5af 100644 --- a/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs +++ b/pkgs/by-name/lf/lf-make-map/src/mapping/map_key.rs @@ -48,8 +48,8 @@ impl PartialOrd for MapKey { } impl MapKey { - pub fn new_from_part_path(part_path: &str, resolution: usize) -> Vec { - let key = Self::part_path_to_key(part_path, resolution); + pub fn new_from_part_path(part_path: &str, resolution: usize, full_path: &str) -> Vec { + let key = Self::path_part_to_key(part_path, resolution, Some(full_path)); key.chars() .map(|ch| Self { @@ -63,7 +63,7 @@ impl MapKey { pub fn new_ones_from_path(path: &str, number_of_chars: usize) -> Vec { let key: Vec = path .split('/') - .flat_map(|part| Self::new_from_part_path(part, number_of_chars)) + .flat_map(|part| Self::new_from_part_path(part, number_of_chars, path)) .collect(); debug!( @@ -80,10 +80,10 @@ impl MapKey { // debug!("Incrementing: '{}' ('{}')", &self, &self.part_path); let added_chars = if new_resolution < self.part_path.len() { - MapKey::part_path_to_key(&self.part_path, new_resolution) + MapKey::path_part_to_key(&self.part_path, new_resolution, None) } else { let mut generated_chars = - MapKey::part_path_to_key(&self.part_path, self.part_path.len()); + MapKey::path_part_to_key(&self.part_path, self.part_path.len(), None); generated_chars.extend( (0..(new_resolution - self.part_path.len())) @@ -112,16 +112,21 @@ impl MapKey { values.iter().map(|value| value.key).collect() } - fn part_path_to_key(part: &str, number_of_chars: usize) -> String { - fn make(pat: char, part: &str, number_of_chars: usize) -> String { + fn path_part_to_key(part: &str, number_of_chars: usize, full_path: Option<&str>) -> String { + fn make(pat: char, part: &str, number_of_chars: usize, full_path: Option<&str>) -> String { let mut acc = String::new(); - if !part.split(pat).all(|part| !part.is_empty()) { + if part.split(pat).all(|split| split.is_empty()) { panic!( "\ -Can't turn this path '{}' to a mapping. -This should not happen, please report the bug!", - part +Failed to split path part `{part}`, with pattern `{pat}`, because all resulting split parts are empty. {} +This should not happen, please report this bug!", { + if let Some(full_path) = full_path { + format!("(Full path was: `{full_path}`)") + } else { + String::new() + } + } ) } @@ -148,9 +153,9 @@ This should not happen, please report the bug!", } let value = if part.contains('_') && !part.starts_with('_') && !part.ends_with('_') { - make('_', part, number_of_chars) + make('_', part, number_of_chars, full_path) } else if part.contains('-') && !part.starts_with('-') && !part.ends_with('-') { - make('-', part, number_of_chars) + make('-', part, number_of_chars, full_path) } else if part.starts_with('.') { // HACK: Special case for directories like ~/.config ~/.local and so on. // We just drop the starting '.' and it's easier to type. <2026-06-02> -- cgit v1.3.1