fix: Remove warnings
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use actix_web::{error, Error, HttpResponse};
|
||||
use actix_web::{Error, HttpResponse};
|
||||
use chrono::{DateTime, Utc};
|
||||
use tera::{self, Context, Function, Tera, Value};
|
||||
use std::error::Error as StdError;
|
||||
use tera::{self, Context, Function, Tera, Value};
|
||||
|
||||
// Export modules
|
||||
pub mod redis_service;
|
||||
@@ -11,6 +11,7 @@ pub use redis_service::RedisCalendarService;
|
||||
|
||||
/// Error type for template rendering
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub struct TemplateError {
|
||||
pub message: String,
|
||||
pub details: String,
|
||||
@@ -46,7 +47,7 @@ impl Function for NowFunction {
|
||||
};
|
||||
|
||||
let now = Utc::now();
|
||||
|
||||
|
||||
// Special case for just getting the year
|
||||
if args.get("year").and_then(|v| v.as_bool()).unwrap_or(false) {
|
||||
return Ok(Value::String(now.format("%Y").to_string()));
|
||||
@@ -68,14 +69,10 @@ impl Function for FormatDateFunction {
|
||||
None => {
|
||||
return Err(tera::Error::msg(
|
||||
"The 'timestamp' argument must be a valid timestamp",
|
||||
))
|
||||
));
|
||||
}
|
||||
},
|
||||
None => {
|
||||
return Err(tera::Error::msg(
|
||||
"The 'timestamp' argument is required",
|
||||
))
|
||||
}
|
||||
None => return Err(tera::Error::msg("The 'timestamp' argument is required")),
|
||||
};
|
||||
|
||||
let format = match args.get("format") {
|
||||
@@ -89,23 +86,21 @@ impl Function for FormatDateFunction {
|
||||
// Convert timestamp to DateTime using the non-deprecated method
|
||||
let datetime = match DateTime::from_timestamp(timestamp, 0) {
|
||||
Some(dt) => dt,
|
||||
None => {
|
||||
return Err(tera::Error::msg(
|
||||
"Failed to convert timestamp to datetime",
|
||||
))
|
||||
}
|
||||
None => return Err(tera::Error::msg("Failed to convert timestamp to datetime")),
|
||||
};
|
||||
|
||||
|
||||
Ok(Value::String(datetime.format(format).to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Formats a date for display
|
||||
#[allow(dead_code)]
|
||||
pub fn format_date(date: &DateTime<Utc>, format: &str) -> String {
|
||||
date.format(format).to_string()
|
||||
}
|
||||
|
||||
/// Truncates a string to a maximum length and adds an ellipsis if truncated
|
||||
#[allow(dead_code)]
|
||||
pub fn truncate_string(s: &str, max_length: usize) -> String {
|
||||
if s.len() <= max_length {
|
||||
s.to_string()
|
||||
@@ -124,38 +119,41 @@ pub fn render_template(
|
||||
ctx: &Context,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
println!("DEBUG: Attempting to render template: {}", template_name);
|
||||
|
||||
|
||||
// Print all context keys for debugging
|
||||
let mut keys = Vec::new();
|
||||
for (key, _) in ctx.clone().into_json().as_object().unwrap().iter() {
|
||||
keys.push(key.clone());
|
||||
}
|
||||
println!("DEBUG: Context keys: {:?}", keys);
|
||||
|
||||
|
||||
match tmpl.render(template_name, ctx) {
|
||||
Ok(content) => {
|
||||
println!("DEBUG: Successfully rendered template: {}", template_name);
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(content))
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
// Log the error with more details
|
||||
println!("DEBUG: Template rendering error for {}: {}", template_name, e);
|
||||
println!(
|
||||
"DEBUG: Template rendering error for {}: {}",
|
||||
template_name, e
|
||||
);
|
||||
println!("DEBUG: Error details: {:?}", e);
|
||||
|
||||
|
||||
// Print the error cause chain for better debugging
|
||||
let mut current_error: Option<&dyn StdError> = Some(&e);
|
||||
let mut error_chain = Vec::new();
|
||||
|
||||
|
||||
while let Some(error) = current_error {
|
||||
error_chain.push(format!("{}", error));
|
||||
current_error = error.source();
|
||||
}
|
||||
|
||||
|
||||
println!("DEBUG: Error chain: {:?}", error_chain);
|
||||
|
||||
|
||||
// Log the error
|
||||
log::error!("Template rendering error: {}", e);
|
||||
|
||||
|
||||
// Create a simple error response with more detailed information
|
||||
let error_html = format!(
|
||||
r#"<!DOCTYPE html>
|
||||
@@ -187,9 +185,9 @@ pub fn render_template(
|
||||
e,
|
||||
error_chain.join("\n")
|
||||
);
|
||||
|
||||
|
||||
println!("DEBUG: Returning simple error page");
|
||||
|
||||
|
||||
Ok(HttpResponse::InternalServerError()
|
||||
.content_type("text/html")
|
||||
.body(error_html))
|
||||
@@ -207,4 +205,4 @@ mod tests {
|
||||
assert_eq!(truncate_string("Hello, world!", 5), "Hello...");
|
||||
assert_eq!(truncate_string("", 5), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user