mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Better error handling
This commit is contained in:
parent
4aa255bf16
commit
0f5b52ff35
1 changed files with 5 additions and 3 deletions
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…
Add table
Add a link
Reference in a new issue