Skip to content

Commit

Permalink
Add more detailed error messages, some nits
Browse files Browse the repository at this point in the history
Signed-off-by: Marcela Melara <[email protected]>
  • Loading branch information
marcelamelara committed Oct 10, 2023
1 parent b2a305a commit 6a10854
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions go/predicates/provenance/v1/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func (m *BuildMetadata) Validate() error {
s := m.GetStartedOn()
if s != nil {
if err := s.CheckValid(); err != nil {
return err
return fmt.Errorf("buildMetadata.startedOn error: %w", err)
}
}

f := m.GetFinishedOn()
if f != nil {
if err := f.CheckValid(); err != nil {
return err
return fmt.Errorf("buildMetadata.finishedOn error: %w", err)
}
}

Expand All @@ -48,11 +48,9 @@ func (b *Builder) Validate() error {

// check that all builderDependencies are valid RDs
builderDeps := b.GetBuilderDependencies()
if len(builderDeps) > 0 {
for i, rd := range builderDeps {
if err := rd.Validate(); err != nil {
return fmt.Errorf("Invalid Builder.BuilderDependencies[%d]: %w", i, err)
}
for i, rd := range builderDeps {
if err := rd.Validate(); err != nil {
return fmt.Errorf("Invalid Builder.BuilderDependencies[%d]: %w", i, err)
}
}

Expand All @@ -73,11 +71,9 @@ func (b *BuildDefinition) Validate() error {

// check that all resolvedDependencies are valid RDs
resolvedDeps := b.GetResolvedDependencies()
if len(resolvedDeps) > 0 {
for i, rd := range resolvedDeps {
if err := rd.Validate(); err != nil {
return fmt.Errorf("Invalid BuildDefinition.ResolvedDependencies[%d]: %w", i, err)
}
for i, rd := range resolvedDeps {
if err := rd.Validate(); err != nil {
return fmt.Errorf("Invalid BuildDefinition.ResolvedDependencies[%d]: %w", i, err)
}
}

Expand All @@ -93,7 +89,7 @@ func (r *RunDetails) Validate() error {

// check the Builder
if err := builder.Validate(); err != nil {
return err
return fmt.Errorf("runDetails.builder error: %w", err)
}

// check the Metadata, if present
Expand All @@ -106,11 +102,9 @@ func (r *RunDetails) Validate() error {

// check that all byproducts are valid RDs
byproducts := r.GetByproducts()
if len(byproducts) > 0 {
for i, rd := range byproducts {
if err := rd.Validate(); err != nil {
return fmt.Errorf("Invalid RunDetails.Byproducts[%d]: %w", i, err)
}
for i, rd := range byproducts {
if err := rd.Validate(); err != nil {
return fmt.Errorf("Invalid RunDetails.Byproducts[%d]: %w", i, err)
}
}

Expand All @@ -126,7 +120,7 @@ func (p *Provenance) Validate() error {

// check the BuildDefinition
if err := buildDef.Validate(); err != nil {
return err
return fmt.Errorf("provenance.buildDefinition error: %w", err)
}

// the runDetails field is required for SLSA Build L1
Expand All @@ -137,7 +131,7 @@ func (p *Provenance) Validate() error {

// check the RunDetails
if err := runDetails.Validate(); err != nil {
return err
return fmt.Errorf("provenance.runDetails error: %w", err)
}

return nil
Expand Down

0 comments on commit 6a10854

Please sign in to comment.