Skip to content

Commit

Permalink
chore: optimize logs output (#3487)
Browse files Browse the repository at this point in the history
  • Loading branch information
zwpaper authored Nov 28, 2024
1 parent 93202d9 commit c442268
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/http-api-bindings/src/embedding/llama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tracing::debug;

use super::{helper::Job, BackgroundJobEvent};

mod error;
mod issues;
mod pulls;

Expand Down
Original file line number Diff line number Diff line change
@@ -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(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
};
Expand Down Expand Up @@ -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
}
};
Expand Down

0 comments on commit c442268

Please sign in to comment.