-
Notifications
You must be signed in to change notification settings - Fork 9
Prevent nil entity in MLE #42
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @AryaHassanli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request addresses an issue where violations found on MasterLists had a nil entity. The change introduces logic to create a matter.Cluster or matter.DeviceType entity for these violations, which is a good improvement. My review includes a couple of suggestions to enhance the code's robustness and maintainability: one to add a default case to the switch statement that creates entities to handle unexpected column types gracefully, and another to refactor the violation creation logic into a helper function to reduce code duplication. Overall, the changes are in the right direction.
mle/process.go
Outdated
| switch idColumn { | ||
| case matter.TableColumnClusterID: | ||
| entity = &matter.Cluster{ | ||
| ID: id, | ||
| Name: name, | ||
| } | ||
| case matter.TableColumnDeviceID: | ||
| entity = &matter.DeviceType{ | ||
| ID: id, | ||
| Name: name, | ||
| } | ||
| } |
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.
To make this function more robust, consider adding a default case to this switch statement. While parseMasterList is currently called only with TableColumnClusterID and TableColumnDeviceID, adding a default case will prevent entity from being implicitly nil if the function is ever used with other idColumn values. This would also help in debugging by logging a warning.
switch idColumn {
case matter.TableColumnClusterID:
entity = &matter.Cluster{
ID: id,
Name: name,
}
case matter.TableColumnDeviceID:
entity = &matter.DeviceType{
ID: id,
Name: name,
}
default:
slog.Warn("unhandled idColumn type in parseMasterList, violation entity will be nil", "idColumn", idColumn.String())
}
mle/process.go
Outdated
| v := spec.Violation{Entity: entity, Type: spec.ViolationMasterList, Text: fmt.Sprintf("Duplicate reserved %s in Master List. ID='%s'", idColumn.String(), id.HexString())} | ||
| v.Path, v.Line = row.Origin() | ||
| violations[v.Path] = append(violations[v.Path], v) |
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 is some repetitive code for creating and adding violations throughout this function. To improve maintainability and reduce duplication, you could extract this logic into a helper function.
For example, you could create a helper like this:
func addMasterListViolation(violations map[string][]spec.Violation, entity types.Entity, row *asciidoc.TableRow, format string, args ...any) {
v := spec.Violation{
Entity: entity,
Type: spec.ViolationMasterList,
Text: fmt.Sprintf(format, args...),
}
v.Path, v.Line = row.Origin()
violations[v.Path] = append(violations[v.Path], v)
}Then, you can simplify the violation reporting calls, for instance:
if _, taken := reserveds[id.Value()]; taken {
addMasterListViolation(violations, entity, row, "Duplicate reserved %s in Master List. ID='%s'", idColumn.String(), id.HexString())
continue
}This would make the code cleaner and easier to manage.
For the violations found on MasterLists we currently set the violation.Entity as nil. This PR, creates an entity representing the cluster or deviceType to be used as violation.Entity.