Skip to content

Commit 6e6b808

Browse files
authored
fix: add case for logs without a source (#9866)
This is to support legacy logs!
1 parent d3220c5 commit 6e6b808

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

site/src/components/Resources/AgentRow.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,32 @@ export const AgentRow: FC<AgentRowProps> = ({
297297
>
298298
{({ index, style }) => {
299299
const log = startupLogs[index];
300-
const sourceIcon: string | undefined =
301-
logSourceByID[log.source_id].icon;
300+
// getLogSource always returns a valid log source.
301+
// This is necessary to support deployments before `coder_script`.
302+
// Existed that haven't restarted their agents.
303+
const getLogSource = (
304+
id: string,
305+
): WorkspaceAgentLogSource => {
306+
return (
307+
logSourceByID[id] || {
308+
created_at: "",
309+
display_name: "Logs",
310+
icon: "",
311+
id: "00000000-0000-0000-0000-000000000000",
312+
workspace_agent_id: "",
313+
}
314+
);
315+
};
316+
const logSource = getLogSource(log.source_id);
302317

303318
let assignedIcon = false;
304319
let icon: JSX.Element;
305320
// If no icon is specified, we show a deterministic
306321
// colored circle to identify unique scripts.
307-
if (sourceIcon) {
322+
if (logSource.icon) {
308323
icon = (
309324
<img
310-
src={sourceIcon}
325+
src={logSource.icon}
311326
alt=""
312327
width={16}
313328
height={16}
@@ -324,7 +339,7 @@ export const AgentRow: FC<AgentRowProps> = ({
324339
height: 16,
325340
marginRight: 8,
326341
background: determineScriptDisplayColor(
327-
logSourceByID[log.source_id].display_name,
342+
logSource.display_name,
328343
),
329344
borderRadius: "100%",
330345
}}
@@ -336,7 +351,7 @@ export const AgentRow: FC<AgentRowProps> = ({
336351
let nextChangesSource = false;
337352
if (index < startupLogs.length - 1) {
338353
nextChangesSource =
339-
logSourceByID[startupLogs[index + 1].source_id].id !==
354+
getLogSource(startupLogs[index + 1].source_id).id !==
340355
log.source_id;
341356
}
342357
// We don't want every line to repeat the icon, because
@@ -346,7 +361,7 @@ export const AgentRow: FC<AgentRowProps> = ({
346361
// same source.
347362
if (
348363
index > 0 &&
349-
logSourceByID[startupLogs[index - 1].source_id].id ===
364+
getLogSource(startupLogs[index - 1].source_id).id ===
350365
log.source_id
351366
) {
352367
icon = (
@@ -396,7 +411,7 @@ export const AgentRow: FC<AgentRowProps> = ({
396411
<Tooltip
397412
title={
398413
<>
399-
{logSourceByID[log.source_id].display_name}
414+
{logSource.display_name}
400415
{assignedIcon && (
401416
<i>
402417
<br />

0 commit comments

Comments
 (0)