From 165699944ab629a94569edb7b05b87623d310290 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Thu, 15 Jun 2023 10:52:27 -0400 Subject: [PATCH] fix: better errors --- main.go | 3 +++ model.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/main.go b/main.go index f9e2c9a..c5e9974 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/model.go b/model.go index 108d4cd..0ff69f8 100644 --- a/model.go +++ b/model.go @@ -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):