Skip to content

Commit 6edd569

Browse files
committed
fix(client): eliminate unreachable code in Close method
Refactor Close() to use early return pattern, removing unreachable return statement that occurred when c.db was nil. The new implementation checks for nil database first, making the control flow clearer and eliminating the code path that could never be executed.
1 parent 4989efd commit 6edd569

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/app/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func (c *PostgreSQLClientImpl) Connect(connectionString string) error {
4040

4141
// Close closes the database connection.
4242
func (c *PostgreSQLClientImpl) Close() error {
43-
if c.db != nil {
44-
if err := c.db.Close(); err != nil {
45-
return fmt.Errorf("failed to close database: %w", err)
46-
}
43+
if c.db == nil {
4744
return nil
4845
}
46+
if err := c.db.Close(); err != nil {
47+
return fmt.Errorf("failed to close database: %w", err)
48+
}
4949
return nil
5050
}
5151

0 commit comments

Comments
 (0)