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:
2026-02-04 01:51:20 +01:00
parent 097b661aed
commit ea11dd5e14
14 changed files with 91 additions and 90 deletions

View File

@@ -12,7 +12,7 @@ func BenchmarkCreateOptions(b *testing.B) {
if err != nil {
b.Fatalf("Failed to create store: %v", err)
}
defer store.Close()
defer store.Close() //nolint:errcheck // benchmark cleanup
ctx := context.Background()
if err := store.Initialize(ctx); err != nil {
@@ -53,7 +53,7 @@ func benchmarkBatch(b *testing.B, batchSize int) {
if err != nil {
b.Fatalf("Failed to create store: %v", err)
}
defer store.Close()
defer store.Close() //nolint:errcheck // benchmark cleanup
ctx := context.Background()
if err := store.Initialize(ctx); err != nil {
@@ -88,9 +88,9 @@ func benchmarkBatch(b *testing.B, batchSize int) {
}
// Clean up for next iteration
store.DeleteRevision(ctx, rev.ID)
_ = store.DeleteRevision(ctx, rev.ID) //nolint:errcheck // benchmark cleanup
rev = &Revision{GitHash: fmt.Sprintf("batchbench%d", i), ChannelName: "bench"}
store.CreateRevision(ctx, rev)
_ = store.CreateRevision(ctx, rev) //nolint:errcheck // benchmark setup
for _, opt := range opts {
opt.RevisionID = rev.ID
}
@@ -102,7 +102,7 @@ func BenchmarkSearchOptions(b *testing.B) {
if err != nil {
b.Fatalf("Failed to create store: %v", err)
}
defer store.Close()
defer store.Close() //nolint:errcheck // benchmark cleanup
ctx := context.Background()
if err := store.Initialize(ctx); err != nil {
@@ -144,7 +144,7 @@ func BenchmarkGetChildren(b *testing.B) {
if err != nil {
b.Fatalf("Failed to create store: %v", err)
}
defer store.Close()
defer store.Close() //nolint:errcheck // benchmark cleanup
ctx := context.Background()
if err := store.Initialize(ctx); err != nil {
@@ -197,7 +197,7 @@ func BenchmarkSchemaInitialize(b *testing.B) {
b.Fatalf("Failed to initialize: %v", err)
}
store.Close()
store.Close() //nolint:errcheck // benchmark cleanup
}
}
@@ -207,7 +207,7 @@ func BenchmarkRevisionCRUD(b *testing.B) {
if err != nil {
b.Fatalf("Failed to create store: %v", err)
}
defer store.Close()
defer store.Close() //nolint:errcheck // benchmark cleanup
ctx := context.Background()
if err := store.Initialize(ctx); err != nil {

View File

@@ -27,7 +27,7 @@ func runStoreTests(t *testing.T, newStore func(t *testing.T) Store) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
store := newStore(t)
defer store.Close()
defer store.Close() //nolint:errcheck // test cleanup
tt.test(t, store)
})
}

View File

@@ -22,7 +22,7 @@ func NewPostgresStore(connStr string) (*PostgresStore, error) {
}
if err := db.Ping(); err != nil {
db.Close()
db.Close() //nolint:errcheck // best-effort cleanup on connection failure
return nil, fmt.Errorf("failed to ping database: %w", err)
}
@@ -185,7 +185,7 @@ func (s *PostgresStore) ListRevisions(ctx context.Context) ([]*Revision, error)
if err != nil {
return nil, fmt.Errorf("failed to list revisions: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var revisions []*Revision
for rows.Next() {
@@ -237,7 +237,7 @@ func (s *PostgresStore) CreateOptionsBatch(ctx context.Context, opts []*Option)
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
defer tx.Rollback() //nolint:errcheck // rollback after commit returns error, which is expected
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO options (revision_id, name, parent_path, type, default_value, example, description, read_only)
@@ -246,7 +246,7 @@ func (s *PostgresStore) CreateOptionsBatch(ctx context.Context, opts []*Option)
if err != nil {
return fmt.Errorf("failed to prepare statement: %w", err)
}
defer stmt.Close()
defer stmt.Close() //nolint:errcheck // statement closed with transaction
for _, opt := range opts {
err := stmt.QueryRowContext(ctx,
@@ -285,7 +285,7 @@ func (s *PostgresStore) GetChildren(ctx context.Context, revisionID int64, paren
if err != nil {
return nil, fmt.Errorf("failed to get children: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var options []*Option
for rows.Next() {
@@ -357,7 +357,7 @@ func (s *PostgresStore) SearchOptions(ctx context.Context, revisionID int64, que
if err != nil {
return nil, fmt.Errorf("failed to search options: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var options []*Option
for rows.Next() {
@@ -390,7 +390,7 @@ func (s *PostgresStore) CreateDeclarationsBatch(ctx context.Context, decls []*De
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
defer tx.Rollback() //nolint:errcheck // rollback after commit returns error, which is expected
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO declarations (option_id, file_path, line)
@@ -399,7 +399,7 @@ func (s *PostgresStore) CreateDeclarationsBatch(ctx context.Context, decls []*De
if err != nil {
return fmt.Errorf("failed to prepare statement: %w", err)
}
defer stmt.Close()
defer stmt.Close() //nolint:errcheck // statement closed with transaction
for _, decl := range decls {
err := stmt.QueryRowContext(ctx, decl.OptionID, decl.FilePath, decl.Line).Scan(&decl.ID)
@@ -419,7 +419,7 @@ func (s *PostgresStore) GetDeclarations(ctx context.Context, optionID int64) ([]
if err != nil {
return nil, fmt.Errorf("failed to get declarations: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var decls []*Declaration
for rows.Next() {
@@ -460,7 +460,7 @@ func (s *PostgresStore) CreateFilesBatch(ctx context.Context, files []*File) err
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
defer tx.Rollback() //nolint:errcheck // rollback after commit returns error, which is expected
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO files (revision_id, file_path, extension, content, byte_size, line_count)
@@ -469,7 +469,7 @@ func (s *PostgresStore) CreateFilesBatch(ctx context.Context, files []*File) err
if err != nil {
return fmt.Errorf("failed to prepare statement: %w", err)
}
defer stmt.Close()
defer stmt.Close() //nolint:errcheck // statement closed with transaction
for _, file := range files {
// Compute metadata if not already set
@@ -516,7 +516,7 @@ func (s *PostgresStore) GetDeclarationsWithMetadata(ctx context.Context, revisio
if err != nil {
return nil, fmt.Errorf("failed to get declarations with metadata: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var decls []*DeclarationWithMetadata
for rows.Next() {

View File

@@ -23,7 +23,7 @@ func NewSQLiteStore(path string) (*SQLiteStore, error) {
// Enable foreign keys
if _, err := db.Exec("PRAGMA foreign_keys = ON"); err != nil {
db.Close()
db.Close() //nolint:errcheck // best-effort cleanup on connection failure
return nil, fmt.Errorf("failed to enable foreign keys: %w", err)
}
@@ -192,7 +192,7 @@ func (s *SQLiteStore) ListRevisions(ctx context.Context) ([]*Revision, error) {
if err != nil {
return nil, fmt.Errorf("failed to list revisions: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration //nolint:errcheck // rows.Err() checked after iteration
var revisions []*Revision
for rows.Next() {
@@ -249,7 +249,7 @@ func (s *SQLiteStore) CreateOptionsBatch(ctx context.Context, opts []*Option) er
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
defer tx.Rollback() //nolint:errcheck // rollback after commit returns error, which is expected
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO options (revision_id, name, parent_path, type, default_value, example, description, read_only)
@@ -257,7 +257,7 @@ func (s *SQLiteStore) CreateOptionsBatch(ctx context.Context, opts []*Option) er
if err != nil {
return fmt.Errorf("failed to prepare statement: %w", err)
}
defer stmt.Close()
defer stmt.Close() //nolint:errcheck // statement closed with transaction
for _, opt := range opts {
result, err := stmt.ExecContext(ctx,
@@ -301,7 +301,7 @@ func (s *SQLiteStore) GetChildren(ctx context.Context, revisionID int64, parentP
if err != nil {
return nil, fmt.Errorf("failed to get children: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var options []*Option
for rows.Next() {
@@ -384,7 +384,7 @@ func (s *SQLiteStore) SearchOptions(ctx context.Context, revisionID int64, query
if err != nil {
return nil, fmt.Errorf("failed to search options: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var options []*Option
for rows.Next() {
@@ -422,7 +422,7 @@ func (s *SQLiteStore) CreateDeclarationsBatch(ctx context.Context, decls []*Decl
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
defer tx.Rollback() //nolint:errcheck // rollback after commit returns error, which is expected
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO declarations (option_id, file_path, line)
@@ -430,7 +430,7 @@ func (s *SQLiteStore) CreateDeclarationsBatch(ctx context.Context, decls []*Decl
if err != nil {
return fmt.Errorf("failed to prepare statement: %w", err)
}
defer stmt.Close()
defer stmt.Close() //nolint:errcheck // statement closed with transaction
for _, decl := range decls {
result, err := stmt.ExecContext(ctx, decl.OptionID, decl.FilePath, decl.Line)
@@ -455,7 +455,7 @@ func (s *SQLiteStore) GetDeclarations(ctx context.Context, optionID int64) ([]*D
if err != nil {
return nil, fmt.Errorf("failed to get declarations: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var decls []*Declaration
for rows.Next() {
@@ -501,7 +501,7 @@ func (s *SQLiteStore) CreateFilesBatch(ctx context.Context, files []*File) error
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
defer tx.Rollback() //nolint:errcheck // rollback after commit returns error, which is expected
stmt, err := tx.PrepareContext(ctx, `
INSERT INTO files (revision_id, file_path, extension, content, byte_size, line_count)
@@ -509,7 +509,7 @@ func (s *SQLiteStore) CreateFilesBatch(ctx context.Context, files []*File) error
if err != nil {
return fmt.Errorf("failed to prepare statement: %w", err)
}
defer stmt.Close()
defer stmt.Close() //nolint:errcheck // statement closed with transaction
for _, file := range files {
// Compute metadata if not already set
@@ -561,7 +561,7 @@ func (s *SQLiteStore) GetDeclarationsWithMetadata(ctx context.Context, revisionI
if err != nil {
return nil, fmt.Errorf("failed to get declarations with metadata: %w", err)
}
defer rows.Close()
defer rows.Close() //nolint:errcheck // rows.Err() checked after iteration
var decls []*DeclarationWithMetadata
for rows.Next() {