github.com/anchore/syft@v1.38.2/internal/unknown/path_error.go (about)

     1  package unknown
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"github.com/anchore/syft/internal/log"
     7  	"github.com/anchore/syft/syft/file"
     8  )
     9  
    10  var pathErrorRegex = regexp.MustCompile(`.*path="([^"]+)".*`)
    11  
    12  // ProcessPathErrors replaces "path" errors returned from the file.Resolver into unknowns,
    13  // and warn logs non-unknown errors, returning only the unknown errors
    14  func ProcessPathErrors(err error) error {
    15  	if err == nil {
    16  		return nil
    17  	}
    18  	errText := err.Error()
    19  	if pathErrorRegex.MatchString(errText) {
    20  		foundPath := pathErrorRegex.ReplaceAllString(err.Error(), "$1")
    21  		if foundPath != "" {
    22  			return New(file.NewLocation(foundPath), err)
    23  		}
    24  	}
    25  	unknowns, remainingErrors := ExtractCoordinateErrors(err)
    26  	log.Debug(remainingErrors)
    27  
    28  	var out []error
    29  	for _, u := range unknowns {
    30  		out = append(out, &u)
    31  	}
    32  	return Join(out...)
    33  }