mirror of
https://github.com/ivabus/pop
synced 2025-06-08 08:00:27 +03:00
fix: better errors
This commit is contained in:
parent
ae6244ee75
commit
165699944a
2 changed files with 17 additions and 0 deletions
3
main.go
3
main.go
|
@ -37,6 +37,9 @@ var rootCmd = &cobra.Command{
|
||||||
if len(to) > 0 && from != "" && subject != "" && body != "" {
|
if len(to) > 0 && from != "" && subject != "" && body != "" {
|
||||||
err := sendEmail(to, from, subject, body, attachments)
|
err := sendEmail(to, from, subject, body, attachments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
cmd.SilenceUsage = true
|
||||||
|
cmd.SilenceErrors = true
|
||||||
|
fmt.Println(errorStyle.Render(err.Error()))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
14
model.go
14
model.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/filepicker"
|
"github.com/charmbracelet/bubbles/filepicker"
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/charmbracelet/bubbles/help"
|
||||||
|
@ -128,6 +129,7 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
picker.CurrentDirectory, _ = os.UserHomeDir()
|
picker.CurrentDirectory, _ = os.UserHomeDir()
|
||||||
|
|
||||||
loadingSpinner := spinner.New()
|
loadingSpinner := spinner.New()
|
||||||
|
loadingSpinner.Style = activeLabelStyle
|
||||||
loadingSpinner.Spinner = spinner.Dot
|
loadingSpinner.Spinner = spinner.Dot
|
||||||
|
|
||||||
m := Model{
|
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) {
|
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case sendEmailSuccessMsg:
|
case sendEmailSuccessMsg:
|
||||||
|
@ -161,7 +171,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
case sendEmailFailureMsg:
|
case sendEmailFailureMsg:
|
||||||
m.state = editingFrom
|
m.state = editingFrom
|
||||||
|
m.focusActiveInput()
|
||||||
m.err = msg
|
m.err = msg
|
||||||
|
return m, clearErrAfter(5 * time.Second)
|
||||||
|
case clearErrMsg:
|
||||||
|
m.err = nil
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, m.keymap.NextInput):
|
case key.Matches(msg, m.keymap.NextInput):
|
||||||
|
|
Loading…
Reference in a new issue