From 8ad1b06be31951bcc8645e58d587490896714a84 Mon Sep 17 00:00:00 2001 From: Amolith Date: Wed, 23 Apr 2025 17:21:44 -0600 Subject: [PATCH] chore: improve error handling and config file creation in main.go Improve error handling in handleCreateTask function by logging the API response body when an error occurs. Update the success message to include the task ID. Modify the createDefaultConfigFile function to use os.OpenFile instead of os.Create for better file handling. --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 64f3f728a288da96a53f6f3dd88d954506305d2b..5315d013438bf23648800d2af3a0828349b867ca 100644 --- a/main.go +++ b/main.go @@ -331,6 +331,7 @@ func handleCreateTask( if resp.StatusCode < 200 || resp.StatusCode >= 300 { respBody, _ := io.ReadAll(resp.Body) + log.Printf("Lunatask API error (status %d): %s", resp.StatusCode, string(respBody)) return &mcp.CallToolResult{ IsError: true, Content: []mcp.Content{mcp.TextContent{Type: "text", Text: fmt.Sprintf("API error (status %d): %s", resp.StatusCode, string(respBody))}}, @@ -353,7 +354,7 @@ func handleCreateTask( Content: []mcp.Content{ mcp.TextContent{ Type: "text", - Text: fmt.Sprint("Task created successfully.", response.Task.ID), + Text: fmt.Sprintf("Task created successfully with ID: %s", response.Task.ID), }, }, }, nil @@ -375,7 +376,7 @@ func createDefaultConfigFile(configPath string) { }}, }}, } - file, err := os.Create(configPath) + file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { log.Fatalf("Failed to create default config at %s: %v", configPath, err) }