Skip to content

Commit

Permalink
Fix lost diags across different mutators (#2057)
Browse files Browse the repository at this point in the history
## Changes
Fix cases where accumulated diagnostics are lost instead of being
propagated further. In some cases it's not possible, add a comment
there.

## Tests
Existing tests
  • Loading branch information
denik authored Dec 31, 2024
1 parent 511db52 commit 3f523b4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bundle/artifacts/expand_globs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (m *expandGlobs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnost
return dyn.SetByPath(v, base, dyn.V(output))
})
if err != nil {
return diag.FromErr(err)
diags = diags.Extend(diag.FromErr(err))
}

return diags
Expand Down
1 change: 1 addition & 0 deletions bundle/config/mutator/resolve_resource_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (m *resolveResourceReferences) Apply(ctx context.Context, b *bundle.Bundle)
})
}

// Note, diags are lost from all goroutines except the first one to return diag
return diag.FromErr(errs.Wait())
}

Expand Down
3 changes: 2 additions & 1 deletion bundle/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func LoadFromBytes(path string, raw []byte) (*Root, diag.Diagnostics) {
// Convert normalized configuration tree to typed configuration.
err = r.updateWithDynamicValue(v)
if err != nil {
return nil, diag.Errorf("failed to load %s: %v", path, err)
diags = diags.Extend(diag.Errorf("failed to load %s: %v", path, err))
return nil, diags
}
return &r, diags
}
Expand Down
3 changes: 2 additions & 1 deletion bundle/config/validate/folder_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func (f *folderPermissions) Apply(ctx context.Context, b bundle.ReadOnlyBundle)
}

if err := g.Wait(); err != nil {
return diag.FromErr(err)
// Note, only diag from first coroutine is captured, others are lost
diags = diags.Extend(diag.FromErr(err))
}

for _, r := range results {
Expand Down

0 comments on commit 3f523b4

Please sign in to comment.