Patch for Issue 21 - #22
Conversation
Summary of ChangesHello @m-tarhon, 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 introduces a crucial improvement to the backend's data normalization process by allowing it to gracefully ignore 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.
Code Review
This pull request updates the normalizeFieldData function to ignore nil values, which aligns with the stated goal. However, the changes introduce two critical issues. First, the plugin will still panic on time-parsing errors, which can cause it to crash. Second, if all values are filtered out, the function returns an empty slice, leading to a panic in the calling createField function due to an out-of-bounds access. I've also included a medium-severity suggestion to log when non-string values are encountered for time fields instead of silently skipping them. Addressing these points will make the plugin more robust and prevent unexpected crashes.
| @@ -264,18 +264,29 @@ func (d *CouchbaseDatasource) query(channel *string, query_data *QueryRequest) b | |||
| } | |||
|
|
|||
| func normalizeFieldData(name string, values []interface{}) (string, []interface{}) { | |||
There was a problem hiding this comment.
This function may now return an empty values slice if all original values are nil or invalid (for time fields). The calling function, createField, does not handle this case and will panic with an "index out of range" error on line 301 when it tries to access values[0].
You should add a check for an empty slice in createField immediately after the call to normalizeFieldData to prevent this panic.
Example fix in createField:
// in createField()
name, values = normalizeFieldData(name, values)
if len(values) == 0 {
// The original check for vlen == 0 can be moved here.
return data.NewField(name, nil, []bool{})
}
// It's now safe to access values[0]
switch v := values[0].(type) {
// ...| } else { | ||
| panic(err) | ||
| } |
There was a problem hiding this comment.
Using panic(err) can crash the plugin if an invalid time string is encountered in the data. It's safer to handle this error by logging it and skipping the problematic value. This makes the plugin more robust against malformed data.
| } else { | |
| panic(err) | |
| } | |
| } else { | |
| log.DefaultLogger.Error("Failed to parse time string, skipping value", "value", timeStr, "error", err) | |
| } |
| } | ||
| // If not a string, skip (or handle as needed) |
There was a problem hiding this comment.
When a value for a time field is not a string, it is silently skipped. This could hide data problems. Consider logging a warning when this happens so that users are aware of potential issues with their data schema or query results.
| } | |
| // If not a string, skip (or handle as needed) | |
| } else { | |
| log.DefaultLogger.Warn("Expected a string for time field, but got a different type; skipping value.", "value", v) | |
| } |
Allows the backend to ignore nils when creating fields