Fix crash bugs: remove impossible nil checks, add bounds check for strings.Fields

- mailManager guaranteed non-nil by constructor, removed defensive checks
- Added bounds check for strings.Fields()[0] in slash command validation
- Removed impossible nil check in processMailboxes()
This commit is contained in:
Levi Neely 2026-02-26 22:28:16 +01:00
parent c10a008f3d
commit addcf0a978
2 changed files with 6 additions and 6 deletions

View File

@ -426,7 +426,11 @@ func (s *Session) Send(ctx context.Context, prompt string) (string, error) {
// Check command support if applicable
if strings.HasPrefix(prompt, "/") && s.commands != nil {
if !s.commands.IsSupported(prompt) {
cmd := strings.Fields(prompt)[0]
fields := strings.Fields(prompt)
cmd := "unknown"
if len(fields) > 0 {
cmd = fields[0]
}
s.mu.Unlock()
return "", fmt.Errorf("slash command not supported by %s backend: %s\nTo use manually, middle-click Attach", s.backendName, cmd)
}

View File

@ -192,10 +192,6 @@ func (m *Manager) mailProcessingLoop() {
// processMailboxes handles outbox delivery and inbox processing
func (m *Manager) processMailboxes() {
if m.mailManager == nil {
return
}
m.mu.RLock()
sessions := make([]backend.Session, 0, len(m.sessions))
for _, sess := range m.sessions {
@ -258,7 +254,7 @@ func (m *Manager) processMailboxes() {
}
}
// GetMailManager returns the mailbox manager
// GetMailManager returns the mailbox manager (guaranteed non-nil)
func (m *Manager) GetMailManager() *mailbox.Manager {
return m.mailManager
}