Skip to content

Commit 38f6076

Browse files
committed
add cli error handling
1 parent bd0e4ca commit 38f6076

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cli.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@ package pzip
22

33
import (
44
"os"
5+
6+
"github.com/pkg/errors"
57
)
68

79
type CLI struct {
810
ArchivePath string
911
DirPath string
1012
}
1113

12-
func (c *CLI) Archive() {
13-
archive, _ := os.Create(c.ArchivePath)
14+
func (c *CLI) Archive() error {
15+
archive, err := os.Create(c.ArchivePath)
16+
if err != nil {
17+
return errors.Errorf("ERROR: could not create archive at %s", c.ArchivePath)
18+
}
1419
defer archive.Close()
1520

16-
archiver, _ := NewArchiver(archive)
21+
archiver, err := NewArchiver(archive)
22+
if err != nil {
23+
return errors.Wrap(err, "ERROR: could not create archiver")
24+
}
1725
defer archiver.Close()
1826

19-
archiver.ArchiveDir(c.DirPath)
27+
err = archiver.ArchiveDir(c.DirPath)
28+
if err != nil {
29+
return errors.Wrapf(err, "ERROR: could not archive directory %s", c.DirPath)
30+
}
31+
32+
return nil
2033
}

0 commit comments

Comments
 (0)