Skip to content

Commit 56bac3a

Browse files
committed
better error logging
1 parent 45827ef commit 56bac3a

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

shai-http/src/apis/openai/completion/handler.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@ pub async fn handle_chat_completion(
5656
}
5757
// Log tool calls
5858
AgentEvent::ToolCallStarted { call, .. } => {
59-
info!("[{}] TOOL {}", session_id, call.tool_name);
59+
info!("[{}] ToolCall: {}", session_id, call.tool_name);
6060
}
6161
AgentEvent::ToolCallCompleted { call, result, .. } => {
6262
use shai_core::tools::ToolResult;
63-
let status = match &result {
64-
ToolResult::Success { .. } => "✓",
65-
ToolResult::Error { .. } => "✗",
66-
ToolResult::Denied => "⊘",
67-
};
68-
info!("[{}] TOOL {} {}", session_id, call.tool_name, status);
63+
match &result {
64+
ToolResult::Success { .. } => {
65+
info!("[{}] ToolResult: {} ✓", session_id, call.tool_name);
66+
}
67+
ToolResult::Error { error, .. } => {
68+
let error_oneline = error.lines().next().unwrap_or(error);
69+
info!("[{}] ToolResult: {} ✗ {}", session_id, call.tool_name, error_oneline);
70+
}
71+
ToolResult::Denied => {
72+
info!("[{}] ToolResult: {} ⊘ Permission denied", session_id, call.tool_name);
73+
}
74+
}
6975
}
7076
// Agent completed or paused - return the result
7177
AgentEvent::Completed { message, success, .. } => {

shai-http/src/apis/openai/response/handler.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn create_response_event_stream(
111111
}
112112
// Tool calls
113113
AgentEvent::ToolCallStarted { call, .. } => {
114-
info!("[{}] TOOL {}", session_id_str, call.tool_name);
114+
info!("[{}] ToolCall: {}", session_id_str, call.tool_name);
115115

116116
let tool_output = ResponseOutput::FunctionToolCall(FunctionToolCall {
117117
id: call.tool_call_id.clone(),
@@ -134,15 +134,16 @@ fn create_response_event_stream(
134134

135135
let tool_status = match &result {
136136
ToolResult::Success { .. } => {
137-
info!("[{}] TOOL {} ✓", session_id_str, call.tool_name);
137+
info!("[{}] ToolResult: {} ✓", session_id_str, call.tool_name);
138138
InputItemStatus::Completed
139139
}
140-
ToolResult::Error { .. } => {
141-
info!("[{}] TOOL {} ✗", session_id_str, call.tool_name);
140+
ToolResult::Error { error, .. } => {
141+
let error_oneline = error.lines().next().unwrap_or(error);
142+
info!("[{}] ToolResult: {} ✗ {}", session_id_str, call.tool_name, error_oneline);
142143
InputItemStatus::Incomplete
143144
}
144145
ToolResult::Denied => {
145-
info!("[{}] TOOL {} ⊘", session_id_str, call.tool_name);
146+
info!("[{}] ToolResult: {} ⊘ Permission denied", session_id_str, call.tool_name);
146147
InputItemStatus::Incomplete
147148
}
148149
};

shai-http/src/apis/simple/handler.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,22 @@ fn log_agent_event(session_id: &Uuid, event: &AgentEvent) {
259259
debug!("[{}] BrainResult", session_id);
260260
}
261261
AgentEvent::ToolCallStarted { call, .. } => {
262-
info!("[{}] TOOL {}", session_id, call.tool_name);
262+
info!("[{}] ToolCall: {}", session_id, call.tool_name);
263263
}
264264
AgentEvent::ToolCallCompleted { call, result, .. } => {
265265
use shai_core::tools::ToolResult;
266-
let status = match result {
267-
ToolResult::Success { .. } => "✓",
268-
ToolResult::Error { .. } => "✗",
269-
ToolResult::Denied => "⊘",
270-
};
271-
info!("[{}] TOOL {} {}", session_id, call.tool_name, status);
266+
match result {
267+
ToolResult::Success { .. } => {
268+
info!("[{}] ToolResult: {} ✓", session_id, call.tool_name);
269+
}
270+
ToolResult::Error { error, .. } => {
271+
let error_oneline = error.lines().next().unwrap_or(error);
272+
info!("[{}] ToolResult: {} ✗ {}", session_id, call.tool_name, error_oneline);
273+
}
274+
ToolResult::Denied => {
275+
info!("[{}] ToolResult: {} ⊘ Permission denied", session_id, call.tool_name);
276+
}
277+
}
272278
}
273279
AgentEvent::Completed { success, .. } => {
274280
info!("[{}] Completed: {}", session_id, if *success { "success" } else { "failed" });

0 commit comments

Comments
 (0)