diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-17 16:35:46 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-17 16:35:46 -0500 |
commit | c8665e658eeab995b26c57aaa95e1d5f08955155 (patch) | |
tree | d99a7e5d2da7fd71202600c2588454013050a8cb | |
parent | d9498148b860252c6f80eb6cd5acbd9fe07b2b8b (diff) |
backend: only call onErr once
-rw-r--r-- | backend.go | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -14,6 +14,7 @@ type Backend struct { fiw *textproto.FIWriter cbr *textproto.CatBlobReader + err error onErr func(error) error } @@ -24,11 +25,21 @@ func NewBackend(fastImport io.Writer, catBlob io.Reader, onErr func(error) error if catBlob != nil { ret.cbr = textproto.NewCatBlobReader(catBlob) } - ret.onErr = onErr + ret.onErr = func(err error) error { + ret.err = err + if onErr != nil { + ret.err = onErr(ret.err) + } + return ret.err + } return ret } func (b *Backend) Do(cmd Cmd) error { + if b.err == nil { + return b.err + } + err := cmd.fiWriteCmd(b.fiw) if err != nil { return b.onErr(err) @@ -37,6 +48,7 @@ func (b *Backend) Do(cmd Cmd) error { if err != nil { return b.onErr(err) } + return nil } |