Skip to content

Commit f51d609

Browse files
committed
Add ExecTimeoutError type
1 parent 9c884d3 commit f51d609

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

modal-go/errors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ type SandboxTimeoutError struct {
100100
func (e SandboxTimeoutError) Error() string {
101101
return "SandboxTimeoutError: " + e.Exception
102102
}
103+
104+
// ExecTimeoutError is returned when a container exec exceeds its execution duration limit.
105+
type ExecTimeoutError struct {
106+
Exception string
107+
}
108+
109+
func (e ExecTimeoutError) Error() string {
110+
return "ExecTimeoutError: " + e.Exception
111+
}

modal-go/task_command_router_client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func (c *TaskCommandRouterClient) ExecPoll(ctx context.Context, taskID, execID s
394394
}.Build()
395395

396396
if deadline != nil && time.Now().After(*deadline) {
397-
return nil, fmt.Errorf("deadline exceeded while polling for exec %s", execID)
397+
return nil, ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while polling for exec %s", execID)}
398398
}
399399

400400
opts := defaultRetryOptions()
@@ -413,7 +413,7 @@ func (c *TaskCommandRouterClient) ExecPoll(ctx context.Context, taskID, execID s
413413
if err != nil {
414414
st, ok := status.FromError(err)
415415
if (ok && st.Code() == codes.DeadlineExceeded) || errors.Is(err, errDeadlineExceeded) {
416-
return nil, fmt.Errorf("deadline exceeded while polling for exec %s", execID)
416+
return nil, ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while polling for exec %s", execID)}
417417
}
418418
}
419419
return resp, err
@@ -427,7 +427,7 @@ func (c *TaskCommandRouterClient) ExecWait(ctx context.Context, taskID, execID s
427427
}.Build()
428428

429429
if deadline != nil && time.Now().After(*deadline) {
430-
return nil, fmt.Errorf("deadline exceeded while waiting for exec %s", execID)
430+
return nil, ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while waiting for exec %s", execID)}
431431
}
432432

433433
opts := retryOptions{
@@ -453,7 +453,7 @@ func (c *TaskCommandRouterClient) ExecWait(ctx context.Context, taskID, execID s
453453
if err != nil {
454454
st, ok := status.FromError(err)
455455
if (ok && st.Code() == codes.DeadlineExceeded) || errors.Is(err, errDeadlineExceeded) {
456-
return nil, fmt.Errorf("deadline exceeded while waiting for exec %s", execID)
456+
return nil, ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while waiting for exec %s", execID)}
457457
}
458458
}
459459
return resp, err
@@ -546,7 +546,7 @@ func (c *TaskCommandRouterClient) streamStdio(
546546
for {
547547
if ctx.Err() != nil {
548548
if deadline != nil && ctx.Err() == context.DeadlineExceeded {
549-
resultCh <- stdioReadResult{Err: fmt.Errorf("deadline exceeded while streaming stdio for exec %s", execID)}
549+
resultCh <- stdioReadResult{Err: ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while streaming stdio for exec %s", execID)}}
550550
} else {
551551
resultCh <- stdioReadResult{Err: ctx.Err()}
552552
}
@@ -574,7 +574,7 @@ func (c *TaskCommandRouterClient) streamStdio(
574574
}
575575
if _, retryable := commandRouterRetryableCodes[status.Code(err)]; retryable && numRetriesRemaining > 0 {
576576
if deadline != nil && time.Until(*deadline) <= delay {
577-
resultCh <- stdioReadResult{Err: fmt.Errorf("deadline exceeded while streaming stdio for exec %s", execID)}
577+
resultCh <- stdioReadResult{Err: ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while streaming stdio for exec %s", execID)}}
578578
return
579579
}
580580
c.logger.DebugContext(ctx, "Retrying stdio read with delay", "delay", delay, "error", err)
@@ -603,7 +603,7 @@ func (c *TaskCommandRouterClient) streamStdio(
603603
}
604604
if _, retryable := commandRouterRetryableCodes[status.Code(err)]; retryable && numRetriesRemaining > 0 {
605605
if deadline != nil && time.Until(*deadline) <= delay {
606-
resultCh <- stdioReadResult{Err: fmt.Errorf("deadline exceeded while streaming stdio for exec %s", execID)}
606+
resultCh <- stdioReadResult{Err: ExecTimeoutError{Exception: fmt.Sprintf("deadline exceeded while streaming stdio for exec %s", execID)}}
607607
return
608608
}
609609
c.logger.DebugContext(ctx, "Retrying stdio read with delay", "delay", delay, "error", err)

0 commit comments

Comments
 (0)