Skip to content

Commit

Permalink
Merge pull request #55 from jjcomer/cache-errors
Browse files Browse the repository at this point in the history
Better Error Handling
  • Loading branch information
jjcomer authored Aug 26, 2020
2 parents ae85f26 + a08d9aa commit d4975ff
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 348 deletions.
80 changes: 53 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ doc = false

[package]
name = 'hogan'
version = '0.8.5'
version = '0.9.0'
authors = [
'Jonathan Morley <jmorley@cvent.com>',
'Josh Comer <jcomer@cvent.com>',
]
edition = '2018'

[dependencies]
failure = '0.1'
anyhow = '1.0'
thiserror = '1.0'
lru_time_cache = '0.10'
handlebars = '3.4'
itertools = '0.9'
Expand Down Expand Up @@ -44,7 +45,7 @@ version = '0.2'
features = ['blocking']

[dependencies.rusqlite]
version = '0.23'
version = '0.24'
features = ['bundled']

[dependencies.git2]
Expand Down
16 changes: 11 additions & 5 deletions src/app/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::app::config::App;
use crate::app::config::AppCommon;
use failure::Error;
use anyhow::{Context, Result};
use hogan::config::ConfigDir;
use hogan::error::HoganError;
use hogan::template::TemplateDir;
use regex::Regex;
use std::fs::File;
Expand All @@ -16,7 +17,7 @@ pub fn cli(
templates_regex: Regex,
common: AppCommon,
ignore_existing: bool,
) -> Result<(), Error> {
) -> Result<()> {
let handlebars = hogan::transform::handlebars(common.strict);

let template_dir = TemplateDir::new(templates_path)?;
Expand Down Expand Up @@ -50,10 +51,15 @@ pub fn cli(
}
Err(e) => Err(e),
} {
bail!("Error transforming {:?} due to {}", rendered.path, e)
return Err(HoganError::UnknownError {
msg: format!("Error transforming {:?} due to {:?}", rendered.path, e),
})
.with_context(|| "Error while ignoring existing");
}
} else if let Err(e) = File::create(&rendered.path)?.write_all(&rendered.contents) {
bail!("Error transforming {:?} due to {}", rendered.path, e)
} else {
File::create(&rendered.path)?
.write_all(&rendered.contents)
.with_context(|| format!("Error transforming {:?}", rendered.path))?;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use failure::Error;
use anyhow::Result;
use hogan::config::ConfigUrl;
use regex::{Regex, RegexBuilder};
use std::path::PathBuf;
Expand Down Expand Up @@ -134,11 +134,11 @@ pub struct AppCommon {
}

impl App {
pub fn config_regex(environment: &Regex) -> Result<Regex, Error> {
pub fn config_regex(environment: &Regex) -> Result<Regex> {
App::parse_regex(&format!("config\\.{}\\.json$", environment))
}

pub fn parse_regex(src: &str) -> Result<Regex, Error> {
pub fn parse_regex(src: &str) -> Result<Regex> {
RegexBuilder::new(src)
.case_insensitive(true)
.build()
Expand Down
8 changes: 4 additions & 4 deletions src/app/datadogstatsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl DdMetrics {
.unwrap_or_else(|err| self.error_msg(name, &err.to_string()));
}

#[allow(dead_code)]
pub fn decr(&self, name: &str, additional_tags: Option<Vec<String>>) {
self.client
.decr(
Expand All @@ -48,6 +49,7 @@ impl DdMetrics {
.unwrap_or_else(|err| self.error_msg(name, &err.to_string()));
}

#[allow(dead_code)]
pub fn gauge(&self, name: &str, additional_tags: Option<Vec<String>>, value: &str) {
self.client
.gauge(
Expand Down Expand Up @@ -80,16 +82,14 @@ impl DdMetrics {
}

pub enum CustomMetrics {
CacheMiss,
CacheHit,
Cache,
RequestTime,
}

impl CustomMetrics {
pub fn metrics_name(self) -> &'static str {
match self {
CustomMetrics::CacheMiss => "hogan.cache_miss.counter",
CustomMetrics::CacheHit => "hogan.cache_hit.counter",
CustomMetrics::Cache => "hogan.cache",
CustomMetrics::RequestTime => "hogan.requests",
}
}
Expand Down
Loading

0 comments on commit d4975ff

Please sign in to comment.