From 6368045a0bb825f1153cc15d5e9b6aa8dcce2692 Mon Sep 17 00:00:00 2001 From: Cheney Date: Thu, 18 Feb 2016 08:41:35 +0800 Subject: [PATCH] report error if it save history fail --- history.go | 16 ++++++++++------ operation.go | 9 ++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/history.go b/history.go index 1441fff..64da6d2 100644 --- a/history.go +++ b/history.go @@ -209,7 +209,7 @@ func (o *opHistory) debug() { } // save history -func (o *opHistory) New(current []rune) { +func (o *opHistory) New(current []rune) (err error) { current = runes.Copy(current) // if just use last command without modify // just clean lastest history @@ -221,7 +221,7 @@ func (o *opHistory) New(current []rune) { o.current = o.history.Back() o.current.Value.(*hisItem).Clean() o.historyVer++ - return + return nil } } } @@ -230,7 +230,7 @@ func (o *opHistory) New(current []rune) { if o.current != nil { o.current.Value.(*hisItem).Clean() o.historyVer++ - return + return nil } } @@ -243,11 +243,13 @@ func (o *opHistory) New(current []rune) { current = runes.Copy(currentItem.Tmp) } - o.Update(current, true) + // err only can be a IO error, just report + err = o.Update(current, true) // push a new one to commit current command o.historyVer++ o.Push(nil) + return } func (o *opHistory) Revert() { @@ -255,7 +257,7 @@ func (o *opHistory) Revert() { o.current = o.history.Back() } -func (o *opHistory) Update(s []rune, commit bool) { +func (o *opHistory) Update(s []rune, commit bool) (err error) { s = runes.Copy(s) if o.current == nil { o.Push(s) @@ -267,13 +269,15 @@ func (o *opHistory) Update(s []rune, commit bool) { if commit { r.Source = s if o.fd != nil { - o.fd.Write([]byte(string(r.Source) + "\n")) + // just report the error + _, err = o.fd.Write([]byte(string(r.Source) + "\n")) } } else { r.Tmp = append(r.Tmp[:0], s...) } o.current.Value = r o.Compact() + return } func (o *opHistory) Push(s []rune) { diff --git a/operation.go b/operation.go index 83d48a1..ffb3fe3 100644 --- a/operation.go +++ b/operation.go @@ -192,7 +192,8 @@ func (o *Operation) ioloop() { } o.outchan <- data if !o.cfg.DisableAutoSaveHistory { - o.history.New(data) + // ignore IO error + _ = o.history.New(data) } else { isUpdateHistory = false } @@ -407,8 +408,10 @@ func (op *Operation) SetConfig(cfg *Config) (*Config, error) { return old, nil } -func (o *Operation) SaveHistory(content string) { - o.history.New([]rune(content)) +// if err is not nil, it just mean it fail to write to file +// other things goes fine. +func (o *Operation) SaveHistory(content string) error { + return o.history.New([]rune(content)) } func (o *Operation) Refresh() {