fix(coderd): improve error handling in chattest, chattool, and chats (#23047)

- Use t.Errorf in chattest non-streaming helpers so encoding
  failures fail the test
- Thread testing.TB into writeResponsesAPIStreaming and log
  SSE write errors instead of silently dropping them
- Bump createworkspace DB error log from Warn to Error
- Use errors.Join for timeout + output error in execute.go
This commit is contained in:
Mathias Fredriksson
2026-03-13 21:41:24 +02:00
committed by GitHub
parent 85509733f3
commit 72689c2552
5 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -201,7 +201,7 @@ func CreateWorkspace(options CreateWorkspaceOptions) fantasy.AgentTool {
Valid: true,
},
}); err != nil {
options.Logger.Warn(ctx, "failed to persist chat workspace association",
options.Logger.Error(ctx, "failed to persist chat workspace association",
slog.F("chat_id", options.ChatID),
slog.F("workspace_id", workspace.ID),
slog.Error(err),
+5 -3
View File
@@ -3,12 +3,14 @@ package chattool
import (
"context"
"encoding/json"
"errors"
"fmt"
"regexp"
"strings"
"time"
"charm.land/fantasy"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/codersdk/workspacesdk"
)
@@ -248,15 +250,15 @@ func pollProcess(
outputResp, outputErr := conn.ProcessOutput(bgCtx, processID)
bgCancel()
output := truncateOutput(outputResp.Output)
timeoutMsg := fmt.Sprintf("command timed out after %s", timeout)
timeoutErr := xerrors.Errorf("command timed out after %s", timeout)
if outputErr != nil {
timeoutMsg += fmt.Sprintf(" (failed to get output: %v)", outputErr)
timeoutErr = errors.Join(timeoutErr, xerrors.Errorf("failed to get output: %w", outputErr))
}
return ExecuteResult{
Success: false,
Output: output,
ExitCode: -1,
Error: timeoutMsg,
Error: timeoutErr.Error(),
Truncated: outputResp.Truncated,
}
case <-ticker.C: