Skip to content

Commit 8d325e2

Browse files
fix: ensure r.scriptComplete is not nil
1 parent afa61eb commit 8d325e2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,20 +340,22 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
340340
stage = proto.Timing_CRON
341341
}
342342

343-
_, err = r.scriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
344-
Timing: &proto.Timing{
345-
ScriptId: script.ID[:],
346-
DisplayName: script.DisplayName,
347-
Start: timestamppb.New(start),
348-
End: timestamppb.New(end),
349-
ExitCode: int32(exitCode),
350-
Stage: stage,
351-
TimedOut: errors.Is(err, ErrTimeout),
352-
},
353-
})
343+
if r.scriptCompleted != nil {
344+
_, err = r.scriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
345+
Timing: &proto.Timing{
346+
ScriptId: script.ID[:],
347+
DisplayName: script.DisplayName,
348+
Start: timestamppb.New(start),
349+
End: timestamppb.New(end),
350+
ExitCode: int32(exitCode),
351+
Stage: stage,
352+
TimedOut: errors.Is(err, ErrTimeout),
353+
},
354+
})
354355

355-
if err != nil {
356-
logger.Error(ctx, fmt.Sprintf("reporting script completed: %s", err.Error()))
356+
if err != nil {
357+
logger.Error(ctx, fmt.Sprintf("reporting script completed: %s", err.Error()))
358+
}
357359
}
358360
}()
359361

0 commit comments

Comments
 (0)