Fix lint errors

This commit is contained in:
Matthew Knight 2026-03-02 19:10:03 -08:00
parent fe4c293adb
commit 83e809dbbb
No known key found for this signature in database
9 changed files with 43 additions and 29 deletions

6
.golangci.yml Normal file
View File

@ -0,0 +1,6 @@
version: "2"
linters:
exclusions:
presets:
- std-error-handling

View File

@ -75,7 +75,9 @@ func main() {
log.Println("Shutting down...") log.Println("Shutting down...")
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second) shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer shutdownCancel() defer shutdownCancel()
srv.Shutdown(shutdownCtx) if err := srv.Shutdown(shutdownCtx); err != nil {
log.Printf("Shutdown error: %v", err)
}
}() }()
log.Printf("Cairn server listening on %s", cfg.ListenAddr) log.Printf("Cairn server listening on %s", cfg.ListenAddr)

View File

@ -183,7 +183,9 @@ func cmdUpload(args []string) error {
} }
var result map[string]any var result map[string]any
json.Unmarshal(body, &result) if err := json.Unmarshal(body, &result); err != nil {
return fmt.Errorf("parsing response: %w", err)
}
fmt.Printf("Artifact uploaded: %s\n", result["id"]) fmt.Printf("Artifact uploaded: %s\n", result["id"])
return nil return nil
@ -244,7 +246,9 @@ func cmdCheck(args []string) error {
Fixed []string `json:"fixed"` Fixed []string `json:"fixed"`
Recurring []string `json:"recurring"` Recurring []string `json:"recurring"`
} }
json.Unmarshal(respBody, &result) if err := json.Unmarshal(respBody, &result); err != nil {
return fmt.Errorf("parsing response: %w", err)
}
if result.IsRegression { if result.IsRegression {
fmt.Printf("REGRESSION: %d new crash signature(s)\n", len(result.New)) fmt.Printf("REGRESSION: %d new crash signature(s)\n", len(result.New))
@ -301,7 +305,9 @@ func cmdCampaign(subcmd string, args []string) error {
return fmt.Errorf("server returned %d: %s", resp.StatusCode, respBody) return fmt.Errorf("server returned %d: %s", resp.StatusCode, respBody)
} }
var result map[string]any var result map[string]any
json.Unmarshal(respBody, &result) if err := json.Unmarshal(respBody, &result); err != nil {
return fmt.Errorf("parsing response: %w", err)
}
fmt.Printf("Campaign started: %s\n", result["id"]) fmt.Printf("Campaign started: %s\n", result["id"])
case "finish": case "finish":

View File

@ -63,12 +63,12 @@ func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
} }
if _, err := tx.Exec(ctx, string(sql)); err != nil { if _, err := tx.Exec(ctx, string(sql)); err != nil {
tx.Rollback(ctx) _ = tx.Rollback(ctx)
return fmt.Errorf("executing migration %s: %w", version, err) return fmt.Errorf("executing migration %s: %w", version, err)
} }
if _, err := tx.Exec(ctx, "INSERT INTO schema_migrations (version) VALUES ($1)", version); err != nil { if _, err := tx.Exec(ctx, "INSERT INTO schema_migrations (version) VALUES ($1)", version); err != nil {
tx.Rollback(ctx) _ = tx.Rollback(ctx)
return fmt.Errorf("recording migration %s: %w", version, err) return fmt.Errorf("recording migration %s: %w", version, err)
} }

View File

@ -124,7 +124,7 @@ func (c *Client) do(ctx context.Context, method, path string, body any) (*http.R
if resp.StatusCode >= 400 { if resp.StatusCode >= 400 {
respBody, _ := io.ReadAll(resp.Body) respBody, _ := io.ReadAll(resp.Body)
resp.Body.Close() _ = resp.Body.Close()
return nil, fmt.Errorf("forgejo API %s %s: %d %s", method, path, resp.StatusCode, string(respBody)) return nil, fmt.Errorf("forgejo API %s %s: %d %s", method, path, resp.StatusCode, string(respBody))
} }
@ -149,6 +149,6 @@ func (c *Client) patch(ctx context.Context, path string, body any) error {
if err != nil { if err != nil {
return err return err
} }
resp.Body.Close() _ = resp.Body.Close()
return nil return nil
} }

View File

@ -42,11 +42,11 @@ func (h *DashboardHandler) Stats(c *gin.Context) {
ctx := c.Request.Context() ctx := c.Request.Context()
var stats DashboardStats var stats DashboardStats
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM artifacts").Scan(&stats.TotalArtifacts) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM artifacts").Scan(&stats.TotalArtifacts)
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM repositories").Scan(&stats.TotalRepos) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM repositories").Scan(&stats.TotalRepos)
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups").Scan(&stats.TotalCrashGroups) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups").Scan(&stats.TotalCrashGroups)
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups WHERE status = 'open'").Scan(&stats.OpenCrashGroups) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups WHERE status = 'open'").Scan(&stats.OpenCrashGroups)
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM campaigns WHERE status = 'running'").Scan(&stats.ActiveCampaigns) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM campaigns WHERE status = 'running'").Scan(&stats.ActiveCampaigns)
// Artifact trend for the last 30 days. // Artifact trend for the last 30 days.
var trend []TrendPoint var trend []TrendPoint

View File

@ -106,7 +106,7 @@ func (h *IngestHandler) Create(c *gin.Context) {
if result := fingerprint.Compute(req.StackTrace); result != nil { if result := fingerprint.Compute(req.StackTrace); result != nil {
sig, isNew, err := models.GetOrCreateSignature(ctx, h.Pool, repo.ID, result.Fingerprint, stackTrace) sig, isNew, err := models.GetOrCreateSignature(ctx, h.Pool, repo.ID, result.Fingerprint, stackTrace)
if err == nil { if err == nil {
models.UpdateArtifactSignature(ctx, h.Pool, artifact.ID, sig.ID, result.Fingerprint) _ = models.UpdateArtifactSignature(ctx, h.Pool, artifact.ID, sig.ID, result.Fingerprint)
if isNew { if isNew {
title := req.Type + " crash in " + req.Repository title := req.Type + " crash in " + req.Repository
@ -115,7 +115,7 @@ func (h *IngestHandler) Create(c *gin.Context) {
} }
group, groupErr := models.CreateCrashGroup(ctx, h.Pool, sig.ID, repo.ID, title) group, groupErr := models.CreateCrashGroup(ctx, h.Pool, sig.ID, repo.ID, title)
if groupErr == nil && h.ForgejoSync != nil { if groupErr == nil && h.ForgejoSync != nil {
h.ForgejoSync.CreateIssueForCrashGroup(ctx, group, req.StackTrace) _ = h.ForgejoSync.CreateIssueForCrashGroup(ctx, group, req.StackTrace)
} }
} }
} }
@ -148,5 +148,5 @@ func (h *DownloadHandler) Download(c *gin.Context) {
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%q", artifact.BlobKey)) c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%q", artifact.BlobKey))
c.Header("Content-Type", "application/octet-stream") c.Header("Content-Type", "application/octet-stream")
io.Copy(c.Writer, reader) _, _ = io.Copy(c.Writer, reader)
} }

View File

@ -53,7 +53,7 @@ func (h *RegressionHandler) Check(c *gin.Context) {
description = fmt.Sprintf("%d new crash signature(s) detected", len(result.New)) description = fmt.Sprintf("%d new crash signature(s) detected", len(result.New))
} }
h.ForgejoSync.Client.CreateCommitStatus(ctx, repo.Owner, repo.Name, req.HeadSHA, forgejo.CommitStatus{ _ = h.ForgejoSync.Client.CreateCommitStatus(ctx, repo.Owner, repo.Name, req.HeadSHA, forgejo.CommitStatus{
State: state, State: state,
Description: description, Description: description,
Context: "cairn/regression", Context: "cairn/regression",

View File

@ -38,8 +38,8 @@ func (h *PageHandler) Index(c *gin.Context) {
} }
var totalCG, openCG int var totalCG, openCG int
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups").Scan(&totalCG) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups").Scan(&totalCG)
h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups WHERE status = 'open'").Scan(&openCG) _ = h.Pool.QueryRow(ctx, "SELECT COUNT(*) FROM crash_groups WHERE status = 'open'").Scan(&openCG)
// Top crashers // Top crashers
type topCrasher struct { type topCrasher struct {
@ -80,7 +80,7 @@ func (h *PageHandler) Index(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "index", data) _ = h.Templates.Render(c.Writer, "index", data)
} }
func (h *PageHandler) Artifacts(c *gin.Context) { func (h *PageHandler) Artifacts(c *gin.Context) {
@ -111,7 +111,7 @@ func (h *PageHandler) Artifacts(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "artifacts", data) _ = h.Templates.Render(c.Writer, "artifacts", data)
} }
func (h *PageHandler) ArtifactDetail(c *gin.Context) { func (h *PageHandler) ArtifactDetail(c *gin.Context) {
@ -128,7 +128,7 @@ func (h *PageHandler) ArtifactDetail(c *gin.Context) {
Content: artifact, Content: artifact,
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "artifact_detail", data) _ = h.Templates.Render(c.Writer, "artifact_detail", data)
} }
func (h *PageHandler) Repos(c *gin.Context) { func (h *PageHandler) Repos(c *gin.Context) {
@ -145,7 +145,7 @@ func (h *PageHandler) Repos(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "repos", data) _ = h.Templates.Render(c.Writer, "repos", data)
} }
func (h *PageHandler) CrashGroups(c *gin.Context) { func (h *PageHandler) CrashGroups(c *gin.Context) {
@ -175,7 +175,7 @@ func (h *PageHandler) CrashGroups(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "crashgroups", data) _ = h.Templates.Render(c.Writer, "crashgroups", data)
} }
func (h *PageHandler) CrashGroupDetail(c *gin.Context) { func (h *PageHandler) CrashGroupDetail(c *gin.Context) {
@ -201,7 +201,7 @@ func (h *PageHandler) CrashGroupDetail(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "crashgroup_detail", data) _ = h.Templates.Render(c.Writer, "crashgroup_detail", data)
} }
func (h *PageHandler) Search(c *gin.Context) { func (h *PageHandler) Search(c *gin.Context) {
@ -222,7 +222,7 @@ func (h *PageHandler) Search(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "search", data) _ = h.Templates.Render(c.Writer, "search", data)
} }
func (h *PageHandler) Regression(c *gin.Context) { func (h *PageHandler) Regression(c *gin.Context) {
@ -252,7 +252,7 @@ func (h *PageHandler) Regression(c *gin.Context) {
Content: content, Content: content,
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "regression", data) _ = h.Templates.Render(c.Writer, "regression", data)
} }
func (h *PageHandler) Campaigns(c *gin.Context) { func (h *PageHandler) Campaigns(c *gin.Context) {
@ -276,7 +276,7 @@ func (h *PageHandler) Campaigns(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "campaigns", data) _ = h.Templates.Render(c.Writer, "campaigns", data)
} }
func (h *PageHandler) CampaignDetail(c *gin.Context) { func (h *PageHandler) CampaignDetail(c *gin.Context) {
@ -301,5 +301,5 @@ func (h *PageHandler) CampaignDetail(c *gin.Context) {
}, },
} }
c.Header("Content-Type", "text/html; charset=utf-8") c.Header("Content-Type", "text/html; charset=utf-8")
h.Templates.Render(c.Writer, "campaign_detail", data) _ = h.Templates.Render(c.Writer, "campaign_detail", data)
} }