@@ -331,6 +331,11 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
331
331
logger .Info (ctx , fmt .Sprintf ("%s script completed" , logPath ), slog .F ("execution_time" , execTime ), slog .F ("exit_code" , exitCode ))
332
332
}
333
333
334
+ if r .scriptCompleted == nil {
335
+ logger .Debug (ctx , "r.scriptCompleted unexpectedly nil" )
336
+ return
337
+ }
338
+
334
339
var stage proto.Timing_Stage
335
340
switch option {
336
341
case ExecuteStartScripts :
@@ -341,21 +346,19 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
341
346
stage = proto .Timing_CRON
342
347
}
343
348
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 ()))
359
362
}
360
363
}()
361
364
0 commit comments