Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: use fmt for error wrapping #12

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/go-chi/chi v4.1.2+incompatible
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/rubenv/sql-migrate v1.6.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -34,6 +33,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions internal/data/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package data

import (
"context"
"fmt"

"github.com/stellar/go/support/errors"
"github.com/stellar/wallet-backend/internal/db"
)

Expand All @@ -15,7 +15,7 @@ func (m *PaymentModel) SubscribeAddress(ctx context.Context, address string) err
const query = `INSERT INTO accounts (stellar_address) VALUES ($1) ON CONFLICT DO NOTHING`
_, err := m.db.ExecContext(ctx, query, address)
if err != nil {
return errors.Wrapf(err, "subscribing address %s to payments tracking", address)
return fmt.Errorf("subscribing address %s to payments tracking: %w", address, err)
}

return nil
Expand All @@ -25,7 +25,7 @@ func (m *PaymentModel) UnsubscribeAddress(ctx context.Context, address string) e
const query = `DELETE FROM accounts WHERE stellar_address = $1`
_, err := m.db.ExecContext(ctx, query, address)
if err != nil {
return errors.Wrapf(err, "unsubscribing address %s to payments tracking", address)
return fmt.Errorf("unsubscribing address %s to payments tracking: %w", address, err)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package db

import (
"context"
"fmt"
"time"

"github.com/jmoiron/sqlx"
"github.com/stellar/go/support/errors"
)

type ConnectionPool interface {
Expand Down Expand Up @@ -34,14 +34,14 @@ const (
func OpenDBConnectionPool(dataSourceName string) (ConnectionPool, error) {
sqlxDB, err := sqlx.Open("postgres", dataSourceName)
if err != nil {
return nil, errors.Wrap(err, "error creating app DB connection pool")
return nil, fmt.Errorf("error creating app DB connection pool: %w", err)
}
sqlxDB.SetConnMaxIdleTime(MaxDBConnIdleTime)
sqlxDB.SetMaxOpenConns(MaxOpenDBConns)

err = sqlxDB.Ping()
if err != nil {
return nil, errors.Wrap(err, "error pinging app DB connection pool")
return nil, fmt.Errorf("error pinging app DB connection pool: %w", err)
}

return &DBConnectionPoolImplementation{DB: sqlxDB}, nil
Expand Down
7 changes: 3 additions & 4 deletions internal/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"

"github.com/go-chi/chi"
"github.com/pkg/errors"
supporthttp "github.com/stellar/go/support/http"
supportlog "github.com/stellar/go/support/log"
"github.com/stellar/go/support/render/health"
Expand All @@ -29,7 +28,7 @@ type handlerDeps struct {
func Serve(cfg Configs) error {
deps, err := getHandlerDeps(cfg)
if err != nil {
return errors.Wrap(err, "setting up handler depedencies")
return fmt.Errorf("setting up handler dependencies: %w", err)
}

addr := fmt.Sprintf(":%d", cfg.Port)
Expand All @@ -50,11 +49,11 @@ func Serve(cfg Configs) error {
func getHandlerDeps(cfg Configs) (handlerDeps, error) {
dbConnectionPool, err := db.OpenDBConnectionPool(cfg.DatabaseURL)
if err != nil {
return handlerDeps{}, errors.Wrap(err, "error connecting to the database")
return handlerDeps{}, fmt.Errorf("error connecting to the database: %w", err)
}
models, err := data.NewModels(dbConnectionPool)
if err != nil {
return handlerDeps{}, errors.Wrap(err, "error creating models for Serve")
return handlerDeps{}, fmt.Errorf("error creating models for Serve: %w", err)
}

return handlerDeps{
Expand Down
Loading