diff options
author | Jan Larres <jan@majutsushi.net> | 2022-07-09 02:38:26 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 16:38:26 +0200 |
commit | aae1ed04babf4c7d8baaad670c076947d7200675 (patch) | |
tree | 883b9130c376c66c76011179ba03201f079126df | |
parent | e4fa652169f14efd0f8ef68131ef0be9c2bf1c67 (diff) |
fix(timings): count time spent on custom on 'when' command failure (#4121)
Count time spent on custom 'when' commands
-rw-r--r-- | src/modules/custom.rs | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/src/modules/custom.rs b/src/modules/custom.rs index 7daea110f..56790f662 100644 --- a/src/modules/custom.rs +++ b/src/modules/custom.rs @@ -34,6 +34,8 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> { } } + let mut module = Module::new(name, config.description, Some(toml_config)); + let mut is_match = context .try_begin_scan()? .set_extensions(&config.detect_extensions) @@ -46,46 +48,42 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> { Either::First(b) => b, Either::Second(s) => exec_when(s, &config, context), }; - - if !is_match { - return None; - } } - let mut module = Module::new(name, config.description, Some(toml_config)); - - let parsed = StringFormatter::new(config.format).and_then(|formatter| { - formatter - .map_meta(|var, _| match var { - "symbol" => Some(config.symbol), - _ => None, - }) - .map_style(|variable| match variable { - "style" => Some(Ok(config.style)), - _ => None, - }) - .map_no_escaping(|variable| match variable { - "output" => { - let output = exec_command(config.command, context, &config)?; - let trimmed = output.trim(); - - if trimmed.is_empty() { - None - } else { - Some(Ok(trimmed.to_string())) + if is_match { + let parsed = StringFormatter::new(config.format).and_then(|formatter| { + formatter + .map_meta(|var, _| match var { + "symbol" => Some(config.symbol), + _ => None, + }) + .map_style(|variable| match variable { + "style" => Some(Ok(config.style)), + _ => None, + }) + .map_no_escaping(|variable| match variable { + "output" => { + let output = exec_command(config.command, context, &config)?; + let trimmed = output.trim(); + + if trimmed.is_empty() { + None + } else { + Some(Ok(trimmed.to_string())) + } } - } - _ => None, - }) - .parse(None, Some(context)) - }); - - match parsed { - Ok(segments) => module.set_segments(segments), - Err(error) => { - log::warn!("Error in module `custom.{}`:\n{}", name, error); - } - }; + _ => None, + }) + .parse(None, Some(context)) + }); + + match parsed { + Ok(segments) => module.set_segments(segments), + Err(error) => { + log::warn!("Error in module `custom.{}`:\n{}", name, error); + } + }; + } let elapsed = start.elapsed(); log::trace!("Took {:?} to compute custom module {:?}", elapsed, name); module.duration = elapsed; |