Skip to content

Commit ed31199

Browse files
fix: debug log on r.scriptCompleted being nil
1 parent 9b43a94 commit ed31199

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
331331
logger.Info(ctx, fmt.Sprintf("%s script completed", logPath), slog.F("execution_time", execTime), slog.F("exit_code", exitCode))
332332
}
333333

334+
if r.scriptCompleted == nil {
335+
logger.Debug(ctx, "r.scriptCompleted unexpectedly nil")
336+
return
337+
}
338+
334339
var stage proto.Timing_Stage
335340
switch option {
336341
case ExecuteStartScripts:
@@ -341,21 +346,19 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
341346
stage = proto.Timing_CRON
342347
}
343348

344-
if r.scriptCompleted != nil {
345-
_, err = r.scriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
346-
Timing: &proto.Timing{
347-
ScriptId: script.ID[:],
348-
DisplayName: script.DisplayName,
349-
Start: timestamppb.New(start),
350-
End: timestamppb.New(end),
351-
ExitCode: int32(exitCode),
352-
Stage: stage,
353-
TimedOut: errors.Is(err, ErrTimeout),
354-
},
355-
})
356-
if err != nil {
357-
logger.Error(ctx, fmt.Sprintf("reporting script completed: %s", err.Error()))
358-
}
349+
_, err = r.scriptCompleted(ctx, &proto.WorkspaceAgentScriptCompletedRequest{
350+
Timing: &proto.Timing{
351+
ScriptId: script.ID[:],
352+
DisplayName: script.DisplayName,
353+
Start: timestamppb.New(start),
354+
End: timestamppb.New(end),
355+
ExitCode: int32(exitCode),
356+
Stage: stage,
357+
TimedOut: errors.Is(err, ErrTimeout),
358+
},
359+
})
360+
if err != nil {
361+
logger.Error(ctx, fmt.Sprintf("reporting script completed: %s", err.Error()))
359362
}
360363
}()
361364

0 commit comments

Comments
 (0)