Skip to content

Commit a87abd4

Browse files
Pnkcahtdgageot
authored andcommitted
fix(editor): prevent thread block when attachment file is deleted
Assisted-By: cagent
1 parent 6621ea9 commit a87abd4

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

pkg/tui/components/editor/editor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,19 @@ func (e *editor) InsertText(text string) {
12731273
e.refreshSuggestion()
12741274
}
12751275

1276-
// AttachFile adds a file as an attachment and inserts @filepath into the editor
1276+
// AttachFile safely adds a file as an attachment and inserts @filepath into the editor.
1277+
// If the file does not exist or is not accessible, the reference is ignored gracefully.
12771278
func (e *editor) AttachFile(filePath string) {
1279+
info, err := os.Stat(filePath)
1280+
if err != nil {
1281+
slog.Warn("AttachFile skipped: cannot access file", "path", filePath, "error", err)
1282+
return
1283+
}
1284+
if info.IsDir() {
1285+
slog.Warn("AttachFile skipped: path is a directory", "path", filePath)
1286+
return
1287+
}
1288+
12781289
placeholder := "@" + filePath
12791290
e.addFileAttachment(placeholder)
12801291
currentValue := e.textarea.Value()

0 commit comments

Comments
 (0)