fix: better errors

This commit is contained in:
Maas Lalani 2023-06-15 10:52:27 -04:00
parent ae6244ee75
commit 165699944a
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
2 changed files with 17 additions and 0 deletions

View file

@ -37,6 +37,9 @@ var rootCmd = &cobra.Command{
if len(to) > 0 && from != "" && subject != "" && body != "" {
err := sendEmail(to, from, subject, body, attachments)
if err != nil {
cmd.SilenceUsage = true
cmd.SilenceErrors = true
fmt.Println(errorStyle.Render(err.Error()))
return err
}
return nil

View file

@ -3,6 +3,7 @@ package main
import (
"os"
"strings"
"time"
"github.com/charmbracelet/bubbles/filepicker"
"github.com/charmbracelet/bubbles/help"
@ -128,6 +129,7 @@ func NewModel(defaults resend.SendEmailRequest) Model {
picker.CurrentDirectory, _ = os.UserHomeDir()
loadingSpinner := spinner.New()
loadingSpinner.Style = activeLabelStyle
loadingSpinner.Spinner = spinner.Dot
m := Model{
@ -154,6 +156,14 @@ func (m Model) Init() tea.Cmd {
)
}
type clearErrMsg struct{}
func clearErrAfter(d time.Duration) tea.Cmd {
return tea.Tick(d, func(t time.Time) tea.Msg {
return clearErrMsg{}
})
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case sendEmailSuccessMsg:
@ -161,7 +171,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
case sendEmailFailureMsg:
m.state = editingFrom
m.focusActiveInput()
m.err = msg
return m, clearErrAfter(5 * time.Second)
case clearErrMsg:
m.err = nil
case tea.KeyMsg:
switch {
case key.Matches(msg, m.keymap.NextInput):