fix(depot): include asset path in invalid-sha error
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,12 +17,10 @@ type manifestFile struct {
|
|||||||
} `yaml:"assets"`
|
} `yaml:"assets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sha256Pattern = regexp.MustCompile(`^[0-9a-f]{64}$`)
|
||||||
|
|
||||||
func ValidSHA(s string) bool {
|
func ValidSHA(s string) bool {
|
||||||
if len(s) != 64 {
|
return sha256Pattern.MatchString(s)
|
||||||
return false
|
|
||||||
}
|
|
||||||
match, _ := regexp.MatchString("^[0-9a-f]{64}$", s)
|
|
||||||
return match
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BlobKey(sha string) string {
|
func BlobKey(sha string) string {
|
||||||
@@ -42,7 +40,7 @@ func ReferencedSHAs(dir string) (map[string]int64, error) {
|
|||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !hasYAMLExt(entry.Name()) {
|
if filepath.Ext(entry.Name()) != ".yml" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +58,7 @@ func ReferencedSHAs(dir string) (map[string]int64, error) {
|
|||||||
|
|
||||||
for _, asset := range manifest.Assets {
|
for _, asset := range manifest.Assets {
|
||||||
if !ValidSHA(asset.SHA256) {
|
if !ValidSHA(asset.SHA256) {
|
||||||
return nil, fmt.Errorf("%s: invalid sha256 hash", entry.Name())
|
return nil, fmt.Errorf("%s: asset %q: invalid sha256 %q", entry.Name(), asset.Path, asset.SHA256)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep the largest size for each sha
|
// Keep the largest size for each sha
|
||||||
@@ -76,7 +74,3 @@ func ReferencedSHAs(dir string) (map[string]int64, error) {
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasYAMLExt(name string) bool {
|
|
||||||
return filepath.Ext(name) == ".yml" || filepath.Ext(name) == ".yaml"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -111,10 +111,11 @@ func TestReferencedSHAs(t *testing.T) {
|
|||||||
|
|
||||||
_, err = ReferencedSHAs(tmpdir)
|
_, err = ReferencedSHAs(tmpdir)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("ReferencedSHAs with bad sha: got nil error, want error naming file")
|
t.Fatalf("ReferencedSHAs with bad sha: got nil error, want error naming file and asset path")
|
||||||
}
|
}
|
||||||
if err != nil && err.Error() != "badsha.yml: invalid sha256 hash" {
|
want := `badsha.yml: asset "file5.txt": invalid sha256 "not_a_valid_sha"`
|
||||||
t.Errorf("ReferencedSHAs error message: got %q, should mention badsha.yml", err.Error())
|
if err.Error() != want {
|
||||||
|
t.Errorf("ReferencedSHAs error message: got %q, want %q", err.Error(), want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user