From 5a13b9892b37e5041224fc773501af7cc6dda37a Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Wed, 19 Jun 2024 14:28:48 -0400 Subject: [PATCH 1/3] chore(clippy): add lint --- src/utils.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.rs b/src/utils.rs index dbaf1de..05a7f7b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use crate::config::get_setting; // // CRATES From 997cd8f829f8be18d4fe051b19d318cf53df7cb3 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Wed, 19 Jun 2024 14:45:32 -0400 Subject: [PATCH 2/3] feat(bug): Improve bug reporting while keeping logs private --- src/client.rs | 12 ++++++------ src/utils.rs | 2 +- templates/error.html | 16 ++++++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/client.rs b/src/client.rs index 5ea9d1c..34934a8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -314,9 +314,9 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo #[cached(size = 100, time = 30, result = true)] pub async fn json(path: String, quarantine: bool) -> Result { // Closure to quickly build errors - let err = |msg: &str, e: String| -> Result { + let err = |msg: &str, e: String, path: String| -> Result { // eprintln!("{} - {}: {}", url, msg, e); - Err(format!("{msg}: {e}")) + Err(format!("{msg}: {e} | {path}")) }; // Fetch the url... @@ -339,7 +339,7 @@ pub async fn json(path: String, quarantine: bool) -> Result { let () = force_refresh_token().await; return Err("OAuth token has expired. Please refresh the page!".to_string()); } - Err(format!("Reddit error {} \"{}\": {}", json["error"], json["reason"], json["message"])) + Err(format!("Reddit error {} \"{}\": {} | {path}", json["error"], json["reason"], json["message"])) } else { Ok(json) } @@ -349,15 +349,15 @@ pub async fn json(path: String, quarantine: bool) -> Result { if status.is_server_error() { Err("Reddit is having issues, check if there's an outage".to_string()) } else { - err("Failed to parse page JSON data", e.to_string()) + err("Failed to parse page JSON data", e.to_string(), path) } } } } - Err(e) => err("Failed receiving body from Reddit", e.to_string()), + Err(e) => err("Failed receiving body from Reddit", e.to_string(), path), } } - Err(e) => err("Couldn't send request to Reddit", e), + Err(e) => err("Couldn't send request to Reddit", e, path), } } diff --git a/src/utils.rs b/src/utils.rs index 05a7f7b..ff75a06 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1029,7 +1029,7 @@ pub fn redirect(path: &str) -> Response { /// Renders a generic error landing page. pub async fn error(req: Request, msg: &str) -> Result, String> { - error!("Error page rendered: {msg}"); + error!("Error page rendered: {}", msg.split("|").next().unwrap_or_default()); let url = req.uri().to_string(); let body = ErrorTemplate { msg: msg.to_string(), diff --git a/templates/error.html b/templates/error.html index a16fc74..e831200 100644 --- a/templates/error.html +++ b/templates/error.html @@ -2,10 +2,14 @@ {% block title %}Error: {{ msg }}{% endblock %} {% block sortstyle %}{% endblock %} {% block content %} -
-

{{ msg }}

-

Reddit Status

-
-

Head back home?

-
+
+

{{ msg }}

+

Reddit Status

+
+

Expected something to work? Report + an issue

+
+

Head back home?

+
{% endblock %} \ No newline at end of file From 9013e589dd67443c4267b8be58286f5c4ea2790a Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Wed, 19 Jun 2024 14:45:55 -0400 Subject: [PATCH 3/3] chore(clippy): fix lint --- src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index ff75a06..f44d037 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1029,7 +1029,7 @@ pub fn redirect(path: &str) -> Response { /// Renders a generic error landing page. pub async fn error(req: Request, msg: &str) -> Result, String> { - error!("Error page rendered: {}", msg.split("|").next().unwrap_or_default()); + error!("Error page rendered: {}", msg.split('|').next().unwrap_or_default()); let url = req.uri().to_string(); let body = ErrorTemplate { msg: msg.to_string(),