Skip to content

Commit 56f2740

Browse files
committed
feat: enhance DownloadLogs component with detailed log formatting and error handling
1 parent 17d4a28 commit 56f2740

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/modules/tasks/DownloadLogs.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,34 @@ export function DownloadLogs({
2525
const iexec = await getIExec();
2626
const logs = await iexec.task.fetchLogs(taskid);
2727

28+
if (!logs || logs.length === 0) {
29+
throw new Error('No logs available for this task');
30+
}
31+
32+
const timestamp = new Date().toISOString();
33+
const header = `Task Logs for ${taskid}\nGenerated on: ${timestamp}\nTotal workers: ${logs.length}\n\n${'='.repeat(80)}\n`;
34+
2835
const logsString =
29-
typeof logs === 'string' ? logs : JSON.stringify(logs, null, 2);
36+
header +
37+
logs
38+
.map(({ worker, stdout, stderr }) => {
39+
let workerLog = `\n----- worker ${worker} -----\n\n`;
40+
41+
if (stdout && stdout.trim()) {
42+
workerLog += `stdout:\n${stdout.trim()}\n\n`;
43+
} else {
44+
workerLog += `stdout: (empty)\n\n`;
45+
}
46+
47+
if (stderr && stderr.trim()) {
48+
workerLog += `stderr:\n${stderr.trim()}\n\n`;
49+
} else {
50+
workerLog += `stderr: (empty)\n\n`;
51+
}
52+
53+
return workerLog;
54+
})
55+
.join('\n' + '='.repeat(80) + '\n');
3056

3157
const blob = new Blob([logsString], { type: 'text/plain' });
3258
const url = URL.createObjectURL(blob);
@@ -64,7 +90,9 @@ export function DownloadLogs({
6490
{isPending ? 'Downloading...' : 'Download logs'}
6591
</Button>
6692
{isError && (
67-
<p className="text-sm text-red-500">Failed to download logs</p>
93+
<p className="text-sm text-red-500">
94+
Failed to download logs, please retry later
95+
</p>
6896
)}
6997
</div>
7098
);

0 commit comments

Comments
 (0)