Skip to content

Commit b5d775c

Browse files
Saranya-jenaHarness
authored andcommitted
fix: [ML-1391]: Fixed issue with occasional failure in download_execution_logs due to pre-existing empty logs directory (#209)
* b92fc4 chore: [ML-1395]: Resolved comments * 5ead1b refactor: simplify log directory creation by removing redundant MkdirAll call (#211) * 97ea96 Merge branch 'master' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/mcp-server into ML-1391 * e3d057 chore: [ML-1391]: Resolved comments * c95a74 fix: [ML-1391]: Fixed issue with occasional failure in download_execution_logs due to pre-existing empty logs directory
1 parent 8950b00 commit b5d775c

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

pkg/harness/tools/logs.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,12 @@ func DownloadExecutionLogsTool(config *config.Config, client *client.LogService)
5757
return mcp.NewToolResultError(err.Error()), nil
5858
}
5959

60-
// Check if logs directory exists, if not create it
61-
_, err = os.Stat(logsDirectory)
62-
if err != nil {
63-
// Directory does not exist, create it
64-
if os.IsNotExist(err) {
65-
createErr := os.Mkdir(logsDirectory, 0755)
66-
if createErr != nil {
67-
return mcp.NewToolResultError(createErr.Error()), nil
68-
}
69-
} else {
70-
return mcp.NewToolResultError(err.Error()), nil
71-
}
72-
}
73-
74-
// Create the logs folder with plan execution ID
60+
// Create the logs folder path (creates all parent directories if needed)
7561
logsFolderName := fmt.Sprintf("logs-%s", planExecutionID)
7662
logsFolderPath := filepath.Join(logsDirectory, logsFolderName)
77-
78-
err = os.Mkdir(logsFolderPath, 0755)
63+
err = os.MkdirAll(logsFolderPath, 0755)
7964
if err != nil {
80-
return mcp.NewToolResultError(fmt.Sprintf("failed to create logs folder: %v", err)), nil
65+
return mcp.NewToolResultError(fmt.Sprintf("failed to create logs directory: %v", err)), nil
8166
}
8267

8368
// Get the download URL

0 commit comments

Comments
 (0)