Skip to content

Commit

Permalink
tar: changes in error handling
Browse files Browse the repository at this point in the history
- Adopt %w as Go 1.12 is no longer supported
- Fix check for permission to open a file: if something that was not a
permission error happened, the code could panic.
  • Loading branch information
fsouza committed Mar 1, 2020
1 parent 12cf609 commit af2ba16
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tar.go
Expand Up @@ -47,7 +47,7 @@ func createTarStream(srcPath, dockerfilePath string) (io.ReadCloser, error) {
}
keepThem, err := fileutils.Matches(includeFile, excludes)
if err != nil {
return nil, fmt.Errorf("cannot match .dockerfile: '%s', error: %s", includeFile, err)
return nil, fmt.Errorf("cannot match .dockerfileignore: '%s', error: %w", includeFile, err)
}
if keepThem {
includes = append(includes, includeFile)
Expand Down Expand Up @@ -85,7 +85,7 @@ func validateContextDirectory(srcPath string, excludes []string) error {

if err != nil {
if os.IsPermission(err) {
return fmt.Errorf("can't stat '%s'", filePath)
return fmt.Errorf("cannot stat %q: %w", filePath, err)
}
if os.IsNotExist(err) {
return nil
Expand All @@ -101,8 +101,8 @@ func validateContextDirectory(srcPath string, excludes []string) error {

if !f.IsDir() {
currentFile, err := os.Open(filePath)
if err != nil && os.IsPermission(err) {
return fmt.Errorf("no permission to read from '%s'", filePath)
if err != nil {
return fmt.Errorf("cannot open %q for reading: %w", filePath, err)
}
currentFile.Close()
}
Expand All @@ -114,7 +114,7 @@ func parseDockerignore(root string) ([]string, error) {
var excludes []string
ignore, err := ioutil.ReadFile(path.Join(root, ".dockerignore"))
if err != nil && !os.IsNotExist(err) {
return excludes, fmt.Errorf("error reading .dockerignore: '%s'", err)
return excludes, fmt.Errorf("error reading .dockerignore: %w", err)
}
excludes = strings.Split(string(ignore), "\n")

Expand Down

0 comments on commit af2ba16

Please sign in to comment.