Skip to content

Commit b178ffd

Browse files
guyernestclaude
andcommitted
fix: Add better JSON parsing error handling and debugging
- Added debug logging for script JSON parsing issues - Attempt to clean common JSON escaping problems - Log the problematic area when JSON parsing fails - This helps diagnose issues with special characters in scripts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b008379 commit b178ffd

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

lambda/tools/local-agent/src-tauri/src/commands.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,41 @@ async fn execute_activity_task(client: &aws_sdk_sfn::Client, token: &str, input:
517517
// New structure: tool_input.script (script is a JSON string)
518518
if let Some(script_str) = tool_input.get("script") {
519519
if let Some(script_json_str) = script_str.as_str() {
520+
// Log the raw script for debugging
521+
add_log("debug", format!("Raw script string length: {}", script_json_str.len()));
522+
523+
// First, try to fix common JSON escaping issues
524+
// Replace problematic escape sequences
525+
let cleaned_json = script_json_str
526+
.replace(r#"\'","#, r#"'","#) // Remove unnecessary escaping of single quotes
527+
.replace(r#"\":"#, r#":"#); // Remove unnecessary escaping of colons
528+
520529
// Parse the script JSON string
521-
match serde_json::from_str(script_json_str) {
530+
match serde_json::from_str(&cleaned_json) {
522531
Ok(script_val) => script_val,
523532
Err(e) => {
524-
add_log("error", format!("Failed to parse script JSON string: {}", e));
525-
let _ = client
526-
.send_task_failure()
527-
.task_token(token)
528-
.error("InvalidScriptJSON")
529-
.cause(&format!("Failed to parse script JSON: {}", e))
530-
.send()
531-
.await;
532-
return;
533+
// Try original string if cleaning didn't help
534+
match serde_json::from_str(script_json_str) {
535+
Ok(script_val) => script_val,
536+
Err(e) => {
537+
add_log("error", format!("Failed to parse script JSON string: {}", e));
538+
// Log a snippet of the problematic area
539+
let col = e.column();
540+
let start = col.saturating_sub(50);
541+
let end = (col + 50).min(script_json_str.len());
542+
if end > start {
543+
add_log("error", format!("Error near position {}: ...{}...", col, &script_json_str[start..end]));
544+
}
545+
let _ = client
546+
.send_task_failure()
547+
.task_token(token)
548+
.error("InvalidScriptJSON")
549+
.cause(&format!("Failed to parse script JSON: {}", e))
550+
.send()
551+
.await;
552+
return;
553+
}
554+
}
533555
}
534556
}
535557
} else {

0 commit comments

Comments
 (0)