fix: add nolint:errcheck comments for intentionally unchecked errors
Add //nolint:errcheck comments to intentionally unchecked error returns: - defer X.Close() calls: errors from closing read-only resources, rows after iteration, files, response bodies, and gzip readers are not actionable and don't affect correctness - defer tx.Rollback(): standard Go pattern where rollback after successful commit returns an error, which is expected behavior - defer stmt.Close(): statements are closed with their transactions - Cleanup operations: DeleteRevision on failure and os.RemoveAll for temp directories are best-effort cleanup - HTTP response encoding: if JSON encoding fails at response time, there's nothing useful we can do - Test/benchmark code: unchecked errors in test setup/cleanup where failures will surface through test assertions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,7 +91,7 @@ func (idx *Indexer) IndexRevision(ctx context.Context, revision string) (*IndexR
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open options.json: %w", err)
|
||||
}
|
||||
defer optionsFile.Close()
|
||||
defer optionsFile.Close() //nolint:errcheck // read-only file
|
||||
|
||||
options, err := ParseOptions(optionsFile)
|
||||
if err != nil {
|
||||
@@ -119,7 +119,7 @@ func (idx *Indexer) IndexRevision(ctx context.Context, revision string) (*IndexR
|
||||
// Store options
|
||||
if err := idx.storeOptions(ctx, rev.ID, options); err != nil {
|
||||
// Cleanup on failure
|
||||
idx.store.DeleteRevision(ctx, rev.ID)
|
||||
_ = idx.store.DeleteRevision(ctx, rev.ID) //nolint:errcheck // best-effort cleanup
|
||||
return nil, fmt.Errorf("failed to store options: %w", err)
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (idx *Indexer) buildOptions(ctx context.Context, ref string) (string, func(
|
||||
}
|
||||
|
||||
cleanup := func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
_ = os.RemoveAll(tmpDir) //nolint:errcheck // best-effort temp dir cleanup
|
||||
}
|
||||
|
||||
// Build options.json using nix-build
|
||||
@@ -280,7 +280,7 @@ func (idx *Indexer) getCommitDate(ctx context.Context, ref string) (time.Time, e
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer resp.Body.Close() //nolint:errcheck // response body read-only
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return time.Time{}, fmt.Errorf("GitHub API returned %d", resp.StatusCode)
|
||||
@@ -362,7 +362,7 @@ func (idx *Indexer) IndexFiles(ctx context.Context, revisionID int64, ref string
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to download tarball: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer resp.Body.Close() //nolint:errcheck // response body read-only
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return 0, fmt.Errorf("download failed with status %d", resp.StatusCode)
|
||||
@@ -373,7 +373,7 @@ func (idx *Indexer) IndexFiles(ctx context.Context, revisionID int64, ref string
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to create gzip reader: %w", err)
|
||||
}
|
||||
defer gz.Close()
|
||||
defer gz.Close() //nolint:errcheck // gzip reader read-only
|
||||
|
||||
tr := tar.NewReader(gz)
|
||||
count := 0
|
||||
|
||||
@@ -77,7 +77,7 @@ func BenchmarkIndexRevision(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
defer store.Close() //nolint:errcheck // benchmark/test cleanup
|
||||
|
||||
ctx := context.Background()
|
||||
if err := store.Initialize(ctx); err != nil {
|
||||
@@ -90,7 +90,7 @@ func BenchmarkIndexRevision(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
// Delete any existing revision first (for repeated runs)
|
||||
if rev, _ := store.GetRevision(ctx, TestNixpkgsRevision); rev != nil {
|
||||
store.DeleteRevision(ctx, rev.ID)
|
||||
_ = store.DeleteRevision(ctx, rev.ID) //nolint:errcheck // benchmark cleanup
|
||||
}
|
||||
|
||||
result, err := indexer.IndexRevision(ctx, TestNixpkgsRevision)
|
||||
@@ -119,7 +119,7 @@ func BenchmarkIndexRevisionWithFiles(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
defer store.Close() //nolint:errcheck // benchmark/test cleanup
|
||||
|
||||
ctx := context.Background()
|
||||
if err := store.Initialize(ctx); err != nil {
|
||||
@@ -132,7 +132,7 @@ func BenchmarkIndexRevisionWithFiles(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
// Delete any existing revision first
|
||||
if rev, _ := store.GetRevision(ctx, TestNixpkgsRevision); rev != nil {
|
||||
store.DeleteRevision(ctx, rev.ID)
|
||||
_ = store.DeleteRevision(ctx, rev.ID) //nolint:errcheck // benchmark cleanup
|
||||
}
|
||||
|
||||
result, err := indexer.IndexRevision(ctx, TestNixpkgsRevision)
|
||||
@@ -168,7 +168,7 @@ func BenchmarkIndexFilesOnly(b *testing.B) {
|
||||
if err != nil {
|
||||
b.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
defer store.Close() //nolint:errcheck // benchmark/test cleanup
|
||||
|
||||
ctx := context.Background()
|
||||
if err := store.Initialize(ctx); err != nil {
|
||||
@@ -211,7 +211,7 @@ func TestIndexRevision(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
defer store.Close() //nolint:errcheck // benchmark/test cleanup
|
||||
|
||||
ctx := context.Background()
|
||||
if err := store.Initialize(ctx); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user