-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor!(collections): don't panic when initializing collections #14323
Conversation
for prefix := range s.schema.collectionsByPrefix { | ||
for prefix2 := range s.schema.collectionsByPrefix { | ||
// don't compare the prefix to itself | ||
if prefix == prefix2 { | ||
continue | ||
} | ||
|
||
// if one prefix is the prefix of the other we have an overlap and | ||
// this schema is corrupt | ||
if strings.HasPrefix(prefix, prefix2) { | ||
return Schema{}, fmt.Errorf("schema has overlapping prefixes 0x%x and 0x%x", prefix, prefix2) | ||
} | ||
} | ||
} |
Check failure
Code scanning / gosec
the value in the range statement should be _ unless copying a map: want: for key := range m
for prefix2 := range s.schema.collectionsByPrefix { | ||
// don't compare the prefix to itself | ||
if prefix == prefix2 { | ||
continue | ||
} | ||
|
||
// if one prefix is the prefix of the other we have an overlap and | ||
// this schema is corrupt | ||
if strings.HasPrefix(prefix, prefix2) { | ||
return Schema{}, fmt.Errorf("schema has overlapping prefixes 0x%x and 0x%x", prefix, prefix2) | ||
} | ||
} |
Check failure
Code scanning / gosec
the value in the range statement should be _ unless copying a map: want: for key := range m
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.
?
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.
LGTM, would maybe like only the panic on re-using a builder to be explicit.
} | ||
|
||
schema := *s.schema | ||
s.schema = nil // this makes the builder unusable |
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.
maybe an explicit panic check is better to debug than a nil pointer dereference I think
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.
added, can you check?
[Cosmos SDK] Kudos, SonarCloud Quality Gate passed! |
[Cosmos SDK - Collections] Kudos, SonarCloud Quality Gate passed! |
Description
This changes the collections API to not panic because of schema errors by using a builder pattern, addressing #14267 (comment)
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change