Skip to content

Commit f5863b2

Browse files
fix(lint): resolve errcheck, unused, and ineffassign violations
- pkg/batch/batch_test.go: check Submit return values, remove unused makeChunks - cmd/api_pipeline.go: check json.Encoder.Encode return values, fix ineffectual assignment in handleBatchResults error path Co-authored-by: Ona <no-reply@ona.com>
1 parent 2c4e975 commit f5863b2

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

cmd/api_pipeline.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (a *PipelineAPI) handlePipeline(w http.ResponseWriter, r *http.Request) {
143143
Stats: marshalStats(stats),
144144
}
145145
w.Header().Set("Content-Type", "application/json")
146-
json.NewEncoder(w).Encode(resp)
146+
_ = json.NewEncoder(w).Encode(resp)
147147
}
148148

149149
// handleBatchSubmit accepts a new batch job.
@@ -170,7 +170,7 @@ func (a *PipelineAPI) handleBatchSubmit(w http.ResponseWriter, r *http.Request)
170170

171171
w.Header().Set("Content-Type", "application/json")
172172
w.WriteHeader(http.StatusAccepted)
173-
json.NewEncoder(w).Encode(BatchSubmitResponse{
173+
_ = json.NewEncoder(w).Encode(BatchSubmitResponse{
174174
JobID: job.ID,
175175
Status: string(job.Status),
176176
})
@@ -221,17 +221,15 @@ func (a *PipelineAPI) handleBatchStatus(w http.ResponseWriter, _ *http.Request,
221221
resp.CompletedAt = job.CompletedAt.UTC().Format("2006-01-02T15:04:05Z")
222222
}
223223
w.Header().Set("Content-Type", "application/json")
224-
json.NewEncoder(w).Encode(resp)
224+
_ = json.NewEncoder(w).Encode(resp)
225225
}
226226

227227
func (a *PipelineAPI) handleBatchResults(w http.ResponseWriter, _ *http.Request, id string) {
228228
chunks, stats, err := a.processor.Results(id)
229229
if err != nil {
230-
code := http.StatusNotFound
230+
code := http.StatusConflict
231231
if err == batch.ErrJobNotFound {
232232
code = http.StatusNotFound
233-
} else {
234-
code = http.StatusConflict
235233
}
236234
http.Error(w, err.Error(), code)
237235
return
@@ -243,7 +241,7 @@ func (a *PipelineAPI) handleBatchResults(w http.ResponseWriter, _ *http.Request,
243241
Stats: marshalStats(stats),
244242
}
245243
w.Header().Set("Content-Type", "application/json")
246-
json.NewEncoder(w).Encode(resp)
244+
_ = json.NewEncoder(w).Encode(resp)
247245
}
248246

249247
// ── helpers ───────────────────────────────────────────────────────────────────

pkg/batch/batch_test.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
package batch
22

33
import (
4-
"fmt"
54
"testing"
65
"time"
76

87
"github.com/Siddhant-K-code/distill/pkg/pipeline"
98
"github.com/Siddhant-K-code/distill/pkg/types"
109
)
1110

12-
func makeChunks(n int) []types.Chunk {
13-
chunks := make([]types.Chunk, n)
14-
for i := range chunks {
15-
chunks[i] = types.Chunk{
16-
ID: fmt.Sprintf("chunk-%d", i),
17-
Text: "test chunk content for batch processing",
18-
}
19-
}
20-
return chunks
21-
}
11+
2212

2313
func TestSubmitAndGet(t *testing.T) {
2414
p := NewProcessor(Config{Workers: 1, QueueSize: 10, ResultTTL: time.Minute})
@@ -84,8 +74,8 @@ func TestList(t *testing.T) {
8474
p := NewProcessor(Config{Workers: 1, QueueSize: 10, ResultTTL: time.Minute})
8575
defer p.Stop()
8676

87-
p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "a", Text: "hello"}}, Options: pipeline.Options{}})
88-
p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "b", Text: "world"}}, Options: pipeline.Options{}})
77+
_, _ = p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "a", Text: "hello"}}, Options: pipeline.Options{}})
78+
_, _ = p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "b", Text: "world"}}, Options: pipeline.Options{}})
8979

9080
// Wait briefly for processing.
9181
time.Sleep(200 * time.Millisecond)
@@ -102,7 +92,7 @@ func TestQueueFull(t *testing.T) {
10292
defer p.Stop()
10393

10494
// Fill the queue.
105-
p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "a", Text: "x"}}, Options: pipeline.Options{}})
95+
_, _ = p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "a", Text: "x"}}, Options: pipeline.Options{}})
10696

10797
// This should fail.
10898
_, err := p.Submit(SubmitRequest{Chunks: []types.Chunk{{ID: "b", Text: "y"}}, Options: pipeline.Options{}})

0 commit comments

Comments
 (0)