Don't send emails when pinging Uptime Kuma fails due to a Kuma bug#12
Conversation
WalkthroughModified Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant deliverSuccessNotification
participant Response
Caller->>deliverSuccessNotification: Call with response
deliverSuccessNotification->>Response: Check status code
alt Status is 404
Response-->>deliverSuccessNotification: 404 status
deliverSuccessNotification->>Response: Read body
Response-->>deliverSuccessNotification: Body content
alt Contains "ok":false AND "Duplicate entry"
rect rgb(144, 238, 144)
deliverSuccessNotification-->>Caller: Return nil (success)
end
else
rect rgb(255, 160, 160)
deliverSuccessNotification-->>Caller: Return error
end
end
else Status is not 404
alt Is 2xx status
rect rgb(144, 238, 144)
deliverSuccessNotification-->>Caller: Return nil (success)
end
else Is non-2xx
rect rgb(255, 160, 160)
deliverSuccessNotification-->>Caller: Return error
end
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
deliver.go (2)
265-265: Consider parsing the JSON response instead of string matching.String matching on JSON content is fragile and could break if the response format changes (e.g., whitespace, field order). Parsing the JSON properly would be more robust.
Consider this approach with JSON parsing:
- if strings.Contains(string(body), "ok\":false") && strings.Contains(string(body), "Duplicate entry") { - return nil - } + var jsonResp map[string]interface{} + if err := json.Unmarshal(body, &jsonResp); err == nil { + if ok, okExists := jsonResp["ok"].(bool); okExists && !ok { + if msg, msgExists := jsonResp["msg"].(string); msgExists && strings.Contains(msg, "Duplicate entry") { + return nil + } + } + }Note: You may need to adjust the JSON field names based on the actual Uptime Kuma response structure.
261-268: Consider adding logging when the workaround is triggered.When this workaround suppresses a 404 error, there's no indication in the logs. Adding a log message would improve observability and help track when the Uptime Kuma bug occurs, which would be useful for debugging and knowing when the workaround can be safely removed.
Example logging (adjust based on your logging framework):
if resp.StatusCode == 404 { body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("failed to GET '%s' (%s, could not read response body: %w)", url, resp.Status, err) } if strings.Contains(string(body), "ok\":false") && strings.Contains(string(body), "Duplicate entry") { // TODO: Add appropriate logging here, e.g.: // log.Printf("Suppressing Uptime Kuma 404 error due to known bug (issue #5357) for URL: %s", url) return nil } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
deliver.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Binaries & Debian Packages
| // special case: don't send failures for intermittent Uptime Kuma bug | ||
| // https://github.com/louislam/uptime-kuma/issues/5357 : | ||
| if resp.StatusCode == 404 { | ||
| body, _ := io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Check the error from io.ReadAll.
Ignoring the error from io.ReadAll could mask I/O failures and lead to incorrect behavior. If reading the body fails, the workaround condition won't be evaluated correctly.
Apply this diff to handle the error:
- body, _ := io.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return fmt.Errorf("failed to GET '%s' (%s, could not read response body: %w)", url, resp.Status, err)
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| body, _ := io.ReadAll(resp.Body) | |
| body, err := io.ReadAll(resp.Body) | |
| if err != nil { | |
| return fmt.Errorf("failed to GET '%s' (%s, could not read response body: %w)", url, resp.Status, err) | |
| } |
🤖 Prompt for AI Agents
In deliver.go around line 264, the io.ReadAll call ignores its error; change it
to capture the error (body, err := io.ReadAll(resp.Body)) and handle err: close
resp.Body if needed, log or wrap and return the error (or propagate it up) so
failures reading the response body don’t get silently ignored and the subsequent
workaround condition is evaluated against a valid body.
Summary by CodeRabbit