diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-27 14:07:22 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-27 14:07:22 -0800 |
commit | 31f920a06aa5d7e7cf363645dac02f6e798fffb1 (patch) | |
tree | ddd60f794c193e1a407e78b5ca94d0a83466fd78 /formats/objfile/writer.go | |
parent | e6855829c4df2861e779adcccbb422e7c0830afd (diff) | |
download | go-git-31f920a06aa5d7e7cf363645dac02f6e798fffb1.tar.gz |
Improved objfile error handling and test coverage
Diffstat (limited to 'formats/objfile/writer.go')
-rw-r--r-- | formats/objfile/writer.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/formats/objfile/writer.go b/formats/objfile/writer.go index d80256c..d9d40f0 100644 --- a/formats/objfile/writer.go +++ b/formats/objfile/writer.go @@ -39,9 +39,18 @@ type Writer struct { // size and type information. Any errors encountered in that process will be // returned in err. // +// If an invalid t is provided, core.ErrInvalidType is returned. If a negative +// size is provided, ErrNegativeSize is returned. +// // The returned Writer implements io.WriteCloser. Close should be called when // finished with the Writer. Close will not close the underlying io.Writer. func NewWriter(w io.Writer, t core.ObjectType, size int64) (*Writer, error) { + if !t.Valid() { + return nil, core.ErrInvalidType + } + if size < 0 { + return nil, ErrNegativeSize + } writer := &Writer{ header: header{t: t, size: size}, } @@ -58,7 +67,7 @@ func (w *Writer) init(output io.Writer) (err error) { err = w.header.Write(w.compressor) if err != nil { - defer w.compressor.Close() + w.compressor.Close() return } |