From 5a611397196f379a2e50f3d48bc8be0bde765c30 Mon Sep 17 00:00:00 2001 From: areille Date: Wed, 2 Sep 2020 09:41:51 +0200 Subject: [PATCH] Add better errors for minifying and upgrade crate --- components/site/Cargo.toml | 2 +- components/site/src/lib.rs | 6 +++--- test_site/templates/index.html | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/site/Cargo.toml b/components/site/Cargo.toml index 60008852..53001d75 100644 --- a/components/site/Cargo.toml +++ b/components/site/Cargo.toml @@ -8,7 +8,7 @@ include = ["src/**/*"] [dependencies] tera = "1" glob = "0.3" -minify-html = "0.3.6" +minify-html = "0.3.8" rayon = "1" serde = "1" serde_derive = "1" diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 61961b79..f3679dc5 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex, RwLock}; use glob::glob; use lazy_static::lazy_static; -use minify_html::{truncate, Cfg}; +use minify_html::{with_friendly_error, Cfg}; use rayon::prelude::*; use tera::{Context, Tera}; @@ -450,13 +450,13 @@ impl Site { fn minify(&self, html: String) -> Result { let cfg = &Cfg { minify_js: false }; let mut input_bytes = html.as_bytes().to_vec(); - match truncate(&mut input_bytes, cfg) { + match with_friendly_error(&mut input_bytes, cfg) { Ok(_len) => match std::str::from_utf8(&mut input_bytes) { Ok(result) => Ok(result.to_string()), Err(err) => bail!("Failed to convert bytes to string : {}", err), }, Err(minify_error) => { - bail!("Failed to truncate html at character {}:", minify_error.position); + bail!("Failed to truncate html at character {}: {} \n {}", minify_error.position, minify_error.message, minify_error.code_context); } } } diff --git a/test_site/templates/index.html b/test_site/templates/index.html index 5a098951..9ed72df3 100644 --- a/test_site/templates/index.html +++ b/test_site/templates/index.html @@ -8,6 +8,8 @@ {% endfor %} + +

<<<

{% endblock content %} {% block script %}