From c44226873a58d087237942111f5235dd708da9b7 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Thu, 28 Nov 2024 15:25:25 +0800 Subject: [PATCH] chore: optimize logs output (#3487) --- crates/http-api-bindings/src/embedding/llama.rs | 4 ++-- .../background_job/third_party_integration.rs | 1 + .../background_job/third_party_integration/error.rs | 12 ++++++++++++ .../background_job/third_party_integration/issues.rs | 3 ++- .../background_job/third_party_integration/pulls.rs | 8 +++++--- 5 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 ee/tabby-webserver/src/service/background_job/third_party_integration/error.rs diff --git a/crates/http-api-bindings/src/embedding/llama.rs b/crates/http-api-bindings/src/embedding/llama.rs index 2f4c2b21eef2..a478cbf0fc34 100644 --- a/crates/http-api-bindings/src/embedding/llama.rs +++ b/crates/http-api-bindings/src/embedding/llama.rs @@ -48,9 +48,9 @@ impl Embedding for LlamaCppEngine { if response.status().is_server_error() { let error = response.text().await?; return Err(anyhow::anyhow!( - "Error from server: {}, prompt: {}", + "Error from server: {}, prompt length: {}", error, - prompt + prompt.len() )); } diff --git a/ee/tabby-webserver/src/service/background_job/third_party_integration.rs b/ee/tabby-webserver/src/service/background_job/third_party_integration.rs index 03c984fa3d45..1a283a4b5365 100644 --- a/ee/tabby-webserver/src/service/background_job/third_party_integration.rs +++ b/ee/tabby-webserver/src/service/background_job/third_party_integration.rs @@ -19,6 +19,7 @@ use tracing::debug; use super::{helper::Job, BackgroundJobEvent}; +mod error; mod issues; mod pulls; diff --git a/ee/tabby-webserver/src/service/background_job/third_party_integration/error.rs b/ee/tabby-webserver/src/service/background_job/third_party_integration/error.rs new file mode 100644 index 000000000000..dd8d993a48dc --- /dev/null +++ b/ee/tabby-webserver/src/service/background_job/third_party_integration/error.rs @@ -0,0 +1,12 @@ +use octocrab; + +pub fn octocrab_error_message(err: octocrab::Error) -> String { + match err { + octocrab::Error::GitHub { source, .. } => { + format!("GitHub error: {} {}", source.status_code, source.message) + } + + // the other errors have impl Display or Debug + _ => err.to_string(), + } +} diff --git a/ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs b/ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs index ecf9d5fbbb92..6f8398a7a0b0 100644 --- a/ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs +++ b/ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs @@ -9,6 +9,7 @@ use tabby_index::public::{ StructuredDoc, StructuredDocFields, StructuredDocIssueFields, StructuredDocState, }; +use super::error::octocrab_error_message; use crate::service::create_gitlab_client; pub async fn list_github_issues( @@ -41,7 +42,7 @@ pub async fn list_github_issues( .await { Ok(x) => x, Err(e) => { - logkit::error!("Failed to fetch issues: {}", e); + logkit::error!("Failed to fetch issues: {}", octocrab_error_message(e)); break; } }; diff --git a/ee/tabby-webserver/src/service/background_job/third_party_integration/pulls.rs b/ee/tabby-webserver/src/service/background_job/third_party_integration/pulls.rs index 3101497cb0e6..c75d1ce1bace 100644 --- a/ee/tabby-webserver/src/service/background_job/third_party_integration/pulls.rs +++ b/ee/tabby-webserver/src/service/background_job/third_party_integration/pulls.rs @@ -6,6 +6,8 @@ use tabby_index::public::{ StructuredDoc, StructuredDocFields, StructuredDocPullDocumentFields, StructuredDocState, }; +use super::error::octocrab_error_message; + pub async fn list_github_pulls( source_id: &str, api_base: &str, @@ -36,7 +38,7 @@ pub async fn list_github_pulls( .await { Ok(x) => x, Err(e) => { - logkit::error!("Failed to fetch pull requests: {}", e); + logkit::error!("Failed to fetch pull requests: {}", octocrab_error_message(e)); break; } }; @@ -73,11 +75,11 @@ pub async fn list_github_pulls( let diff = match octocrab.pulls(&owner, &repo).get_diff(pull.number).await { Ok(x) if x.len() < 1024*1024*10 => x, Ok(_) => { - logkit::warn!("Pull request {} diff is larger than 10MB, skipping", url); continue } Err(e) => { - logkit::error!("Failed to fetch pull request diff for {}: {}", url, e); + logkit::error!("Failed to fetch pull request diff for {}: {}", + url, octocrab_error_message(e)); continue } };