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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user