Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05fa48d

Browse files
committed
fix(coderd): chat: avoid panic if no messages are accumulated
1 parentccefabe commit05fa48d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

‎coderd/chat.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/coder/coder/v2/coderd/database/dbtime"
1515
"github.com/coder/coder/v2/coderd/httpapi"
1616
"github.com/coder/coder/v2/coderd/httpmw"
17+
"github.com/coder/coder/v2/coderd/util/strings"
1718
"github.com/coder/coder/v2/codersdk"
1819
"github.com/coder/coder/v2/codersdk/toolsdk"
1920
)
@@ -224,10 +225,19 @@ func (api *API) postChatMessages(w http.ResponseWriter, r *http.Request) {
224225
})
225226
return
226227
}
228+
varnewTitlestring
229+
accMessages:=acc.Messages()
230+
// If for some reason the stream didn't return any messages, use the
231+
// original message as the title.
232+
iflen(accMessages)==0 {
233+
newTitle=strings.Truncate(messages[0].Content,40)
234+
}else {
235+
newTitle=strings.Truncate(accMessages[0].Content,40)
236+
}
227237
err=api.Database.UpdateChatByID(ctx, database.UpdateChatByIDParams{
228238
ID:chat.ID,
229-
Title:acc.Messages()[0].Content,
230-
UpdatedAt:time.Now(),
239+
Title:newTitle,
240+
UpdatedAt:dbtime.Now(),
231241
})
232242
iferr!=nil {
233243
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp