-
Notifications
You must be signed in to change notification settings - Fork 167
fix(sidebar): prevent null responses from sidebar API endpoints #974
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -118,18 +118,23 @@ | |||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func (p *Plugin) writeJSON(w http.ResponseWriter, v any) { | ||||||||||||||||||||||||||||||||||||||||||
| b, err := json.Marshal(v) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| p.client.Log.Error("Failed to marshal JSON response", "error", err.Error()) | ||||||||||||||||||||||||||||||||||||||||||
| w.WriteHeader(http.StatusInternalServerError) | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| _, err = w.Write(b) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| p.client.Log.Error("Failed to write JSON response", "error", err.Error()) | ||||||||||||||||||||||||||||||||||||||||||
| w.WriteHeader(http.StatusInternalServerError) | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| w.Header().Set("Content-Type", "application/json") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if v == nil { | ||||||||||||||||||||||||||||||||||||||||||
| v = map[string]any{} | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| b, err := json.Marshal(v) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| p.client.Log.Error("Failed to marshal JSON response", "error", err.Error()) | ||||||||||||||||||||||||||||||||||||||||||
| w.WriteHeader(http.StatusInternalServerError) | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _, err = w.Write(b) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| p.client.Log.Error("Failed to write JSON response", "error", err.Error()) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func (p *Plugin) writeAPIError(w http.ResponseWriter, apiErr *APIErrorResponse) { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -713,9 +718,9 @@ | |||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| if cErr != nil { | ||||||||||||||||||||||||||||||||||||||||||
| c.Log.WithError(cErr).Warnf("Failed to list notifications") | ||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| c.Log.WithError(cErr).Warnf("Failed to list notifications") | ||||||||||||||||||||||||||||||||||||||||||
| return []*FilteredNotification{} | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| filteredNotifications := []*FilteredNotification{} | ||||||||||||||||||||||||||||||||||||||||||
| for _, n := range notifications { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1040,8 +1045,15 @@ | |||||||||||||||||||||||||||||||||||||||||
| func (p *Plugin) getSidebarData(c *UserContext) (*SidebarContent, error) { | ||||||||||||||||||||||||||||||||||||||||||
| reviewResp, assignmentResp, openPRResp, err := p.getLHSData(c) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| c.Log.WithError(err).Warn("Sidebar data fetch failed") | ||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 1048 in server/plugin/api.go
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return &SidebarContent{ | ||||||||||||||||||||||||||||||||||||||||||
| PRs: []*graphql.GithubPRDetails{}, | ||||||||||||||||||||||||||||||||||||||||||
| Reviews: []*graphql.GithubPRDetails{}, | ||||||||||||||||||||||||||||||||||||||||||
| Assignments: []*github.Issue{}, | ||||||||||||||||||||||||||||||||||||||||||
| Unreads: []*FilteredNotification{}, | ||||||||||||||||||||||||||||||||||||||||||
| }, nil | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return &SidebarContent{ | ||||||||||||||||||||||||||||||||||||||||||
| PRs: openPRResp, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1053,13 +1065,18 @@ | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func (p *Plugin) getSidebarContent(c *UserContext, w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||||||||||||||||||||||||
| sidebarContent, err := p.getSidebarData(c) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| c.Log.WithError(err).Errorf("Failed to search for the sidebar data") | ||||||||||||||||||||||||||||||||||||||||||
| p.writeAPIError(w, &APIErrorResponse{Message: "failed to search for the sidebar data", StatusCode: http.StatusInternalServerError}) | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil || sidebarContent == nil { | ||||||||||||||||||||||||||||||||||||||||||
| c.Log.Warn("Sidebar content empty, returning defaults") | ||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 1069 in server/plugin/api.go
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| sidebarContent = &SidebarContent{ | ||||||||||||||||||||||||||||||||||||||||||
| PRs: []*graphql.GithubPRDetails{}, | ||||||||||||||||||||||||||||||||||||||||||
| Reviews: []*graphql.GithubPRDetails{}, | ||||||||||||||||||||||||||||||||||||||||||
| Assignments: []*github.Issue{}, | ||||||||||||||||||||||||||||||||||||||||||
| Unreads: []*FilteredNotification{}, | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1068
to
+1077
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build failure: Same issue as above - use Additionally, note that this defensive block is now effectively unreachable: 🐛 Proposed fix if err != nil || sidebarContent == nil {
- c.Log.Warn("Sidebar content empty, returning defaults")
+ c.Log.Warnf("Sidebar content empty, returning defaults")
sidebarContent = &SidebarContent{📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: plugin-ci / test[failure] 1069-1069: 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| p.writeJSON(w, sidebarContent) | ||||||||||||||||||||||||||||||||||||||||||
| p.writeJSON(w, sidebarContent) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func (p *Plugin) postToDo(c *UserContext, w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
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.
Build failure:
Warnmethod does not exist onlogger.Logger.The static analysis indicates that
logger.Loggerhas no methodWarn. UseWarnfinstead, which is consistent with other logging calls in this file (e.g., line 721).🐛 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: plugin-ci / test
[failure] 1048-1048:
c.Log.WithError(err).Warn undefined (type logger.Logger has no field or method Warn)
🤖 Prompt for AI Agents