1
0
mirror of https://github.com/schollz/croc.git synced 2024-12-26 23:35:48 +03:00

Better error handling

This commit is contained in:
Zack Scholl 2017-10-21 14:34:59 -06:00
parent 4aa255bf16
commit 0f5b52ff35

View File

@ -7,23 +7,25 @@ import (
"math"
"os"
"strconv"
"github.com/pkg/errors"
)
func CatFiles(files []string, outfile string, remove ...bool) error {
finished, err := os.Create(outfile)
defer finished.Close()
if err != nil {
return err
return errors.Wrap(err, "CatFiles create: ")
}
for i := range files {
fh, err := os.Open(files[i])
if err != nil {
return err
return errors.Wrap(err, "CatFiles open "+files[i]+": ")
}
_, err = io.Copy(finished, fh)
if err != nil {
return err
return errors.Wrap(err, "CatFiles copy: ")
}
fh.Close()
if len(remove) > 0 && remove[0] {