mirror of
https://github.com/schollz/croc.git
synced 2024-12-27 15:55:41 +03:00
Better error handling
This commit is contained in:
parent
4aa255bf16
commit
0f5b52ff35
8
utils.go
8
utils.go
@ -7,23 +7,25 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CatFiles(files []string, outfile string, remove ...bool) error {
|
func CatFiles(files []string, outfile string, remove ...bool) error {
|
||||||
finished, err := os.Create(outfile)
|
finished, err := os.Create(outfile)
|
||||||
defer finished.Close()
|
defer finished.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "CatFiles create: ")
|
||||||
}
|
}
|
||||||
for i := range files {
|
for i := range files {
|
||||||
fh, err := os.Open(files[i])
|
fh, err := os.Open(files[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "CatFiles open "+files[i]+": ")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(finished, fh)
|
_, err = io.Copy(finished, fh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err, "CatFiles copy: ")
|
||||||
}
|
}
|
||||||
fh.Close()
|
fh.Close()
|
||||||
if len(remove) > 0 && remove[0] {
|
if len(remove) > 0 && remove[0] {
|
||||||
|
Loading…
Reference in New Issue
Block a user