-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch nil values for FoundSubjectsByResourceID map and return as errors #1008
Conversation
internal/graph/lookupsubjects.go
Outdated
@@ -460,7 +464,10 @@ func (lsu *lookupSubjectsUnion) CompletedChildOperations() error { | |||
|
|||
for _, result := range collector.Results() { | |||
metadata = combineResponseMetadata(metadata, result.Metadata) | |||
foundSubjects.UnionWith(result.FoundSubjectsByResourceId) | |||
err := foundSubjects.UnionWith(result.FoundSubjectsByResourceId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use the if err := thing(); err != nil
pattern here and at other callsites.
internal/graph/lookupsubjects.go
Outdated
foundSubjects.UnionWith(result.FoundSubjectsByResourceId) | ||
err := foundSubjects.UnionWith(result.FoundSubjectsByResourceId) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap these errors with higher level context about why you were trying to Union, so we can trace which callsite caused the problem.
@@ -36,12 +42,22 @@ func (ssr SubjectSetByResourceID) AddFromRelationship(relationship *core.Relatio | |||
} | |||
|
|||
// UnionWith unions the map's sets with the other map of sets provided. | |||
func (ssr SubjectSetByResourceID) UnionWith(other map[string]*v1.FoundSubjects) { | |||
func (ssr SubjectSetByResourceID) UnionWith(other map[string]*v1.FoundSubjects) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create a test which reproduces why this happens in real running-systems to verify the fix?
fe88057
to
a59ac72
Compare
Updated |
for _, subject := range subjects.FoundSubjects { | ||
ssr.add(resourceID, subject) | ||
err := ssr.add(resourceID, subject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := ...; err != nil
Also ensure we never add nils in the first place
a59ac72
to
5518ee1
Compare
Also ensure we never add nils in the first place