diff --git a/cmd/doc_events.go b/cmd/doc_events.go index 1c59b0cc9..262a5588a 100644 --- a/cmd/doc_events.go +++ b/cmd/doc_events.go @@ -2,9 +2,9 @@ package cmd import ( "encoding/json" + "fmt" "github.com/formancehq/ledger/internal/bus" "github.com/invopop/jsonschema" - "github.com/pkg/errors" "github.com/spf13/cobra" "os" "path/filepath" @@ -21,12 +21,12 @@ func NewDocEventsCommand() *cobra.Command { writeDir, err := cmd.Flags().GetString(writeDirFlag) if err != nil { - return errors.Wrap(err, "failed to get write-dir flag") + return fmt.Errorf("failed to get write-dir flag: %w", err) } err = os.MkdirAll(writeDir, 0755) if err != nil { - return errors.Wrap(err, "failed to create write-dir") + return fmt.Errorf("failed to create write-dir: %w", err) } for _, o := range []any{ @@ -38,11 +38,11 @@ func NewDocEventsCommand() *cobra.Command { schema := jsonschema.Reflect(o) data, err := json.MarshalIndent(schema, "", " ") if err != nil { - return errors.Wrap(err, "failed to marshal schema") + return fmt.Errorf("failed to marshal schema: %w", err) } err = os.WriteFile(filepath.Join(writeDir, reflect.TypeOf(o).Name()+".json"), data, 0600) if err != nil { - return errors.Wrap(err, "failed to write schema") + return fmt.Errorf("failed to write schema: %w", err) } } diff --git a/cmd/serve.go b/cmd/serve.go index f0f5651fe..e0340b9eb 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "github.com/formancehq/ledger/internal/storage/driver" "net/http" @@ -20,7 +21,6 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" systemcontroller "github.com/formancehq/ledger/internal/controller/system" "github.com/formancehq/ledger/internal/storage" - "github.com/pkg/errors" "github.com/formancehq/go-libs/ballast" "github.com/formancehq/go-libs/service" diff --git a/internal/api/common/middleware_resolver.go b/internal/api/common/middleware_resolver.go index 6a5e6af89..e713844b9 100644 --- a/internal/api/common/middleware_resolver.go +++ b/internal/api/common/middleware_resolver.go @@ -10,7 +10,7 @@ import ( "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/platform/postgres" - "github.com/pkg/errors" + "errors" ) const ( diff --git a/internal/api/common/middleware_resolver_test.go b/internal/api/common/middleware_resolver_test.go index 85454dc9c..05a4240ec 100644 --- a/internal/api/common/middleware_resolver_test.go +++ b/internal/api/common/middleware_resolver_test.go @@ -6,11 +6,11 @@ import ( "net/http/httptest" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/logging" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" systemcontroller "github.com/formancehq/ledger/internal/controller/system" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v1/controllers_accounts.go b/internal/api/v1/controllers_accounts.go index 6f7b740e2..26a552604 100644 --- a/internal/api/v1/controllers_accounts.go +++ b/internal/api/v1/controllers_accounts.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/pkg/errors" + "errors" "github.com/formancehq/go-libs/query" ledger "github.com/formancehq/ledger/internal" diff --git a/internal/api/v1/controllers_accounts_add_metadata.go b/internal/api/v1/controllers_accounts_add_metadata.go index 028365949..a582b322b 100644 --- a/internal/api/v1/controllers_accounts_add_metadata.go +++ b/internal/api/v1/controllers_accounts_add_metadata.go @@ -7,11 +7,11 @@ import ( "net/http" "net/url" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func addAccountMetadata(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v1/controllers_accounts_count.go b/internal/api/v1/controllers_accounts_count.go index d427c9bb1..38b2c0df4 100644 --- a/internal/api/v1/controllers_accounts_count.go +++ b/internal/api/v1/controllers_accounts_count.go @@ -4,12 +4,12 @@ import ( "fmt" "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func countAccounts(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v1/controllers_accounts_count_test.go b/internal/api/v1/controllers_accounts_count_test.go index 0d75c6d92..2cfeb8a0b 100644 --- a/internal/api/v1/controllers_accounts_count_test.go +++ b/internal/api/v1/controllers_accounts_count_test.go @@ -6,12 +6,12 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/query" "github.com/formancehq/go-libs/time" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v1/controllers_accounts_delete_metadata_test.go b/internal/api/v1/controllers_accounts_delete_metadata_test.go index 815d3caa1..f26eff44d 100644 --- a/internal/api/v1/controllers_accounts_delete_metadata_test.go +++ b/internal/api/v1/controllers_accounts_delete_metadata_test.go @@ -7,11 +7,11 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/logging" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v1/controllers_accounts_list.go b/internal/api/v1/controllers_accounts_list.go index a6d7641a2..730b37fb9 100644 --- a/internal/api/v1/controllers_accounts_list.go +++ b/internal/api/v1/controllers_accounts_list.go @@ -3,12 +3,12 @@ package v1 import ( "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func listAccounts(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v1/controllers_logs_list.go b/internal/api/v1/controllers_logs_list.go index c2e8bb969..eb75346e0 100644 --- a/internal/api/v1/controllers_logs_list.go +++ b/internal/api/v1/controllers_logs_list.go @@ -1,6 +1,7 @@ package v1 import ( + "fmt" "net/http" "github.com/formancehq/go-libs/api" @@ -8,7 +9,6 @@ import ( "github.com/formancehq/go-libs/query" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func buildGetLogsQuery(r *http.Request) (query.Builder, error) { @@ -42,7 +42,7 @@ func getLogs(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get(QueryKeyCursor) != "" { err := bunpaginate.UnmarshalCursor(r.URL.Query().Get(QueryKeyCursor), &query) if err != nil { - api.BadRequest(w, ErrValidation, errors.Errorf("invalid '%s' query param", QueryKeyCursor)) + api.BadRequest(w, ErrValidation, fmt.Errorf("invalid '%s' query param: %w", QueryKeyCursor, err)) return } } else { diff --git a/internal/api/v1/controllers_transactions_add_metadata.go b/internal/api/v1/controllers_transactions_add_metadata.go index 35dcc4f12..1a3a3fe4e 100644 --- a/internal/api/v1/controllers_transactions_add_metadata.go +++ b/internal/api/v1/controllers_transactions_add_metadata.go @@ -7,11 +7,11 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func addTransactionMetadata(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v1/controllers_transactions_create.go b/internal/api/v1/controllers_transactions_create.go index 5ec0b7540..e80038aa8 100644 --- a/internal/api/v1/controllers_transactions_create.go +++ b/internal/api/v1/controllers_transactions_create.go @@ -8,12 +8,12 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/api/common" - "github.com/pkg/errors" ) type Script struct { @@ -38,11 +38,11 @@ func (s Script) ToCore() (*ledgercontroller.Script, error) { // Is a monetary var asset string if err := json.Unmarshal(m["asset"], &asset); err != nil { - return nil, errors.Wrap(err, "unmarshalling asset") + return nil, fmt.Errorf("unmarshalling asset: %w", err) } amount := &big.Int{} if err := json.Unmarshal(m["amount"], amount); err != nil { - return nil, errors.Wrap(err, "unmarshalling amount") + return nil, fmt.Errorf("unmarshalling amount: %w", err) } s.Script.Vars[k] = fmt.Sprintf("%s %s", asset, amount) diff --git a/internal/api/v1/controllers_transactions_delete_metadata.go b/internal/api/v1/controllers_transactions_delete_metadata.go index 79a4f2993..261529bfd 100644 --- a/internal/api/v1/controllers_transactions_delete_metadata.go +++ b/internal/api/v1/controllers_transactions_delete_metadata.go @@ -6,10 +6,10 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func deleteTransactionMetadata(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v1/controllers_transactions_delete_metadata_test.go b/internal/api/v1/controllers_transactions_delete_metadata_test.go index 20134e87d..fb047db15 100644 --- a/internal/api/v1/controllers_transactions_delete_metadata_test.go +++ b/internal/api/v1/controllers_transactions_delete_metadata_test.go @@ -7,11 +7,11 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/logging" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v1/controllers_transactions_revert.go b/internal/api/v1/controllers_transactions_revert.go index 9d115fda0..fec50f5f1 100644 --- a/internal/api/v1/controllers_transactions_revert.go +++ b/internal/api/v1/controllers_transactions_revert.go @@ -6,10 +6,10 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func revertTransaction(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v1/middleware_auto_create_ledger.go b/internal/api/v1/middleware_auto_create_ledger.go index dba8c65b5..f3240a333 100644 --- a/internal/api/v1/middleware_auto_create_ledger.go +++ b/internal/api/v1/middleware_auto_create_ledger.go @@ -3,7 +3,7 @@ package v1 import ( "net/http" - "github.com/pkg/errors" + "errors" "github.com/formancehq/ledger/internal/controller/system" diff --git a/internal/api/v2/controllers_accounts_add_metadata.go b/internal/api/v2/controllers_accounts_add_metadata.go index 2db572523..e0a2a3150 100644 --- a/internal/api/v2/controllers_accounts_add_metadata.go +++ b/internal/api/v2/controllers_accounts_add_metadata.go @@ -6,11 +6,11 @@ import ( "net/http" "net/url" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func addAccountMetadata(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_accounts_count.go b/internal/api/v2/controllers_accounts_count.go index 1d8b85f93..55c34d6af 100644 --- a/internal/api/v2/controllers_accounts_count.go +++ b/internal/api/v2/controllers_accounts_count.go @@ -4,10 +4,10 @@ import ( "fmt" "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func countAccounts(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_accounts_count_test.go b/internal/api/v2/controllers_accounts_count_test.go index fc4900b70..d4fd216ec 100644 --- a/internal/api/v2/controllers_accounts_count_test.go +++ b/internal/api/v2/controllers_accounts_count_test.go @@ -7,12 +7,12 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/query" "github.com/formancehq/go-libs/time" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_accounts_delete_metadata_test.go b/internal/api/v2/controllers_accounts_delete_metadata_test.go index c0ce238dd..e216fcdcc 100644 --- a/internal/api/v2/controllers_accounts_delete_metadata_test.go +++ b/internal/api/v2/controllers_accounts_delete_metadata_test.go @@ -7,11 +7,11 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/logging" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_accounts_list.go b/internal/api/v2/controllers_accounts_list.go index 40254ad65..5c9578c00 100644 --- a/internal/api/v2/controllers_accounts_list.go +++ b/internal/api/v2/controllers_accounts_list.go @@ -3,12 +3,12 @@ package v2 import ( "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func listAccounts(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_accounts_list_test.go b/internal/api/v2/controllers_accounts_list_test.go index dc76f339d..ed2a45ee3 100644 --- a/internal/api/v2/controllers_accounts_list_test.go +++ b/internal/api/v2/controllers_accounts_list_test.go @@ -7,6 +7,7 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/bun/bunpaginate" @@ -15,7 +16,6 @@ import ( "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_balances.go b/internal/api/v2/controllers_balances.go index ff752e9d3..450f75c2a 100644 --- a/internal/api/v2/controllers_balances.go +++ b/internal/api/v2/controllers_balances.go @@ -3,8 +3,8 @@ package v2 import ( "net/http" + "errors" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" diff --git a/internal/api/v2/controllers_bulk.go b/internal/api/v2/controllers_bulk.go index 82d8552d8..a2d976a71 100644 --- a/internal/api/v2/controllers_bulk.go +++ b/internal/api/v2/controllers_bulk.go @@ -6,11 +6,11 @@ import ( "fmt" "net/http" + "errors" "github.com/formancehq/go-libs/metadata" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/formancehq/ledger/internal/tracing" - "github.com/pkg/errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" diff --git a/internal/api/v2/controllers_bulk_test.go b/internal/api/v2/controllers_bulk_test.go index b77fc5c21..4229f9e77 100644 --- a/internal/api/v2/controllers_bulk_test.go +++ b/internal/api/v2/controllers_bulk_test.go @@ -15,11 +15,11 @@ import ( "github.com/formancehq/go-libs/time" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/metadata" ledger "github.com/formancehq/ledger/internal" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_ledgers_create.go b/internal/api/v2/controllers_ledgers_create.go index 2998074b3..f6c6cc44b 100644 --- a/internal/api/v2/controllers_ledgers_create.go +++ b/internal/api/v2/controllers_ledgers_create.go @@ -9,9 +9,9 @@ import ( ledger "github.com/formancehq/ledger/internal" + "errors" "github.com/formancehq/go-libs/api" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func createLedger(systemController system.Controller) http.HandlerFunc { diff --git a/internal/api/v2/controllers_ledgers_create_test.go b/internal/api/v2/controllers_ledgers_create_test.go index 9a7b33c85..768e25c03 100644 --- a/internal/api/v2/controllers_ledgers_create_test.go +++ b/internal/api/v2/controllers_ledgers_create_test.go @@ -9,10 +9,10 @@ import ( "github.com/formancehq/ledger/internal/controller/system" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/logging" ledger "github.com/formancehq/ledger/internal" - "github.com/pkg/errors" "github.com/formancehq/go-libs/auth" "github.com/google/uuid" diff --git a/internal/api/v2/controllers_ledgers_delete_metadata_test.go b/internal/api/v2/controllers_ledgers_delete_metadata_test.go index b08108bee..4fe7fe784 100644 --- a/internal/api/v2/controllers_ledgers_delete_metadata_test.go +++ b/internal/api/v2/controllers_ledgers_delete_metadata_test.go @@ -6,8 +6,8 @@ import ( "net/http/httptest" "testing" + "errors" "github.com/formancehq/go-libs/api" - "github.com/pkg/errors" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/logging" diff --git a/internal/api/v2/controllers_ledgers_list.go b/internal/api/v2/controllers_ledgers_list.go index 7b9ca90db..10bc18f9e 100644 --- a/internal/api/v2/controllers_ledgers_list.go +++ b/internal/api/v2/controllers_ledgers_list.go @@ -3,12 +3,12 @@ package v2 import ( "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/pointer" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/formancehq/ledger/internal/controller/system" - "github.com/pkg/errors" ) func listLedgers(b system.Controller) http.HandlerFunc { diff --git a/internal/api/v2/controllers_ledgers_list_test.go b/internal/api/v2/controllers_ledgers_list_test.go index 74279c44e..ed78614d0 100644 --- a/internal/api/v2/controllers_ledgers_list_test.go +++ b/internal/api/v2/controllers_ledgers_list_test.go @@ -7,6 +7,7 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/bun/bunpaginate" @@ -14,7 +15,6 @@ import ( ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/google/uuid" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_ledgers_update_metadata.go b/internal/api/v2/controllers_ledgers_update_metadata.go index cafc35401..4b1d510e4 100644 --- a/internal/api/v2/controllers_ledgers_update_metadata.go +++ b/internal/api/v2/controllers_ledgers_update_metadata.go @@ -4,11 +4,11 @@ import ( "encoding/json" "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" systemcontroller "github.com/formancehq/ledger/internal/controller/system" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func updateLedgerMetadata(systemController systemcontroller.Controller) http.HandlerFunc { diff --git a/internal/api/v2/controllers_logs_export_test.go b/internal/api/v2/controllers_logs_export_test.go index cee4a37b9..6df3b93ba 100644 --- a/internal/api/v2/controllers_logs_export_test.go +++ b/internal/api/v2/controllers_logs_export_test.go @@ -7,11 +7,11 @@ import ( "net/http/httptest" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) @@ -46,7 +46,7 @@ func TestLogsExport(t *testing.T) { } log := ledger.NewTransactionLog(ledger.CreatedTransaction{ - Transaction: ledger.NewTransaction(), + Transaction: ledger.NewTransaction(), AccountMetadata: ledger.AccountMetadata{}, }) diff --git a/internal/api/v2/controllers_logs_import.go b/internal/api/v2/controllers_logs_import.go index 524871b47..a12a5124d 100644 --- a/internal/api/v2/controllers_logs_import.go +++ b/internal/api/v2/controllers_logs_import.go @@ -7,10 +7,10 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/api/common" - "github.com/pkg/errors" ) func importLogs(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_logs_import_test.go b/internal/api/v2/controllers_logs_import_test.go index 8d43184b9..853a59994 100644 --- a/internal/api/v2/controllers_logs_import_test.go +++ b/internal/api/v2/controllers_logs_import_test.go @@ -9,10 +9,10 @@ import ( "testing" "time" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" ledger "github.com/formancehq/ledger/internal" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_logs_list.go b/internal/api/v2/controllers_logs_list.go index 89ad39e98..3596b99d5 100644 --- a/internal/api/v2/controllers_logs_list.go +++ b/internal/api/v2/controllers_logs_list.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" + "errors" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/bun/bunpaginate" diff --git a/internal/api/v2/controllers_logs_list_test.go b/internal/api/v2/controllers_logs_list_test.go index 69b87deca..7971da1dc 100644 --- a/internal/api/v2/controllers_logs_list_test.go +++ b/internal/api/v2/controllers_logs_list_test.go @@ -9,6 +9,7 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/bun/bunpaginate" @@ -16,7 +17,6 @@ import ( "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_transactions_add_metadata.go b/internal/api/v2/controllers_transactions_add_metadata.go index 2cae7eef6..181695bac 100644 --- a/internal/api/v2/controllers_transactions_add_metadata.go +++ b/internal/api/v2/controllers_transactions_add_metadata.go @@ -7,11 +7,11 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func addTransactionMetadata(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_transactions_add_metadata_test.go b/internal/api/v2/controllers_transactions_add_metadata_test.go index 443dcd229..aebee20c8 100644 --- a/internal/api/v2/controllers_transactions_add_metadata_test.go +++ b/internal/api/v2/controllers_transactions_add_metadata_test.go @@ -7,7 +7,7 @@ import ( "net/url" "testing" - "github.com/pkg/errors" + "errors" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" diff --git a/internal/api/v2/controllers_transactions_count.go b/internal/api/v2/controllers_transactions_count.go index df5434055..31face73c 100644 --- a/internal/api/v2/controllers_transactions_count.go +++ b/internal/api/v2/controllers_transactions_count.go @@ -4,10 +4,10 @@ import ( "fmt" "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func countTransactions(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_transactions_count_test.go b/internal/api/v2/controllers_transactions_count_test.go index fcbe1d890..ef9e81528 100644 --- a/internal/api/v2/controllers_transactions_count_test.go +++ b/internal/api/v2/controllers_transactions_count_test.go @@ -8,12 +8,12 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/query" "github.com/formancehq/go-libs/time" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_transactions_create.go b/internal/api/v2/controllers_transactions_create.go index c6d98be15..20cbc1d5e 100644 --- a/internal/api/v2/controllers_transactions_create.go +++ b/internal/api/v2/controllers_transactions_create.go @@ -6,9 +6,9 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" - "github.com/pkg/errors" ) func createTransaction(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_transactions_create_test.go b/internal/api/v2/controllers_transactions_create_test.go index 2977209d3..74bf9897d 100644 --- a/internal/api/v2/controllers_transactions_create_test.go +++ b/internal/api/v2/controllers_transactions_create_test.go @@ -10,11 +10,11 @@ import ( "github.com/formancehq/go-libs/time" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_transactions_delete_metadata.go b/internal/api/v2/controllers_transactions_delete_metadata.go index 0b4a26f70..bccf79a6e 100644 --- a/internal/api/v2/controllers_transactions_delete_metadata.go +++ b/internal/api/v2/controllers_transactions_delete_metadata.go @@ -8,8 +8,8 @@ import ( "github.com/go-chi/chi/v5" + "errors" "github.com/formancehq/ledger/internal/api/common" - "github.com/pkg/errors" "github.com/formancehq/go-libs/api" ) diff --git a/internal/api/v2/controllers_transactions_delete_metadata_test.go b/internal/api/v2/controllers_transactions_delete_metadata_test.go index 78a5e1779..ebbc2c861 100644 --- a/internal/api/v2/controllers_transactions_delete_metadata_test.go +++ b/internal/api/v2/controllers_transactions_delete_metadata_test.go @@ -7,11 +7,11 @@ import ( "net/url" "testing" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/go-libs/logging" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) diff --git a/internal/api/v2/controllers_transactions_list.go b/internal/api/v2/controllers_transactions_list.go index 739b758f9..16657c25a 100644 --- a/internal/api/v2/controllers_transactions_list.go +++ b/internal/api/v2/controllers_transactions_list.go @@ -3,12 +3,12 @@ package v2 import ( "net/http" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/ledger/internal/api/common" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) func listTransactions(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_transactions_revert.go b/internal/api/v2/controllers_transactions_revert.go index a83d145ab..9fd787e49 100644 --- a/internal/api/v2/controllers_transactions_revert.go +++ b/internal/api/v2/controllers_transactions_revert.go @@ -6,10 +6,10 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" + "errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" "github.com/go-chi/chi/v5" - "github.com/pkg/errors" ) func revertTransaction(w http.ResponseWriter, r *http.Request) { diff --git a/internal/api/v2/controllers_volumes.go b/internal/api/v2/controllers_volumes.go index 6b72ede04..1d22e433e 100644 --- a/internal/api/v2/controllers_volumes.go +++ b/internal/api/v2/controllers_volumes.go @@ -3,8 +3,8 @@ package v2 import ( "net/http" + "errors" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/formancehq/go-libs/api" "github.com/formancehq/ledger/internal/api/common" diff --git a/internal/controller/ledger/controller_default.go b/internal/controller/ledger/controller_default.go index 30d7d5aaa..5c5d38e3a 100644 --- a/internal/controller/ledger/controller_default.go +++ b/internal/controller/ledger/controller_default.go @@ -22,7 +22,7 @@ import ( "github.com/formancehq/go-libs/pointer" "github.com/google/uuid" // todo: remove as it is in maintenance mode - "github.com/pkg/errors" + "errors" ledger "github.com/formancehq/ledger/internal" ) @@ -92,7 +92,7 @@ func (ctrl *DefaultController) Import(ctx context.Context, stream chan ledger.Lo // Due to the serializable isolation level, and since we explicitly ask for the ledger state in the sql transaction context // if the state change, the sql transaction will be aborted with a serialization error if err := sqlTx.LockLedger(ctx); err != nil { - return false, errors.Wrap(err, "failed to lock ledger") + return false, fmt.Errorf("failed to lock ledger: %w", err) } // We can import only if the ledger is empty. @@ -100,7 +100,7 @@ func (ctrl *DefaultController) Import(ctx context.Context, stream chan ledger.Lo PageSize: 1, })) if err != nil { - return false, errors.Wrap(err, "error listing logs") + return false, fmt.Errorf("error listing logs: %w", err) } if len(logs.Data) > 0 { @@ -109,7 +109,7 @@ func (ctrl *DefaultController) Import(ctx context.Context, stream chan ledger.Lo for log := range stream { if err := ctrl.importLog(ctx, sqlTx, log); err != nil { - return false, errors.Wrapf(err, "importing log %d", log.ID) + return false, fmt.Errorf("importing log %d: %w", log.ID, err) } } @@ -128,47 +128,47 @@ func (ctrl *DefaultController) importLog(ctx context.Context, sqlTx TX, log ledg switch payload := log.Data.(type) { case ledger.CreatedTransaction: if err := sqlTx.CommitTransaction(ctx, &payload.Transaction); err != nil { - return errors.Wrap(err, "failed to commit transaction") + return fmt.Errorf("failed to commit transaction: %w", err) } if len(payload.AccountMetadata) > 0 { if err := sqlTx.UpdateAccountsMetadata(ctx, payload.AccountMetadata); err != nil { - return errors.Wrapf(err, "updating metadata of accounts '%s'", Keys(payload.AccountMetadata)) + return fmt.Errorf("updating metadata of accounts '%s': %w", Keys(payload.AccountMetadata), err) } } case ledger.RevertedTransaction: _, _, err := sqlTx.RevertTransaction(ctx, payload.RevertedTransaction.ID) if err != nil { - return errors.Wrap(err, "failed to revert transaction") + return fmt.Errorf("failed to revert transaction: %w", err) } case ledger.SavedMetadata: switch payload.TargetType { case ledger.MetaTargetTypeTransaction: if _, _, err := sqlTx.UpdateTransactionMetadata(ctx, payload.TargetID.(int), payload.Metadata); err != nil { - return errors.Wrap(err, "failed to update transaction metadata") + return fmt.Errorf("failed to update transaction metadata: %w", err) } case ledger.MetaTargetTypeAccount: if err := sqlTx.UpdateAccountsMetadata(ctx, ledger.AccountMetadata{ payload.TargetID.(string): payload.Metadata, }); err != nil { - return errors.Wrap(err, "failed to update account metadata") + return fmt.Errorf("failed to update account metadata: %w", err) } } case ledger.DeletedMetadata: switch payload.TargetType { case ledger.MetaTargetTypeTransaction: if _, _, err := sqlTx.DeleteTransactionMetadata(ctx, payload.TargetID.(int), payload.Key); err != nil { - return errors.Wrap(err, "failed to delete transaction metadata") + return fmt.Errorf("failed to delete transaction metadata: %w", err) } case ledger.MetaTargetTypeAccount: if err := sqlTx.DeleteAccountMetadata(ctx, payload.TargetID.(string), payload.Key); err != nil { - return errors.Wrap(err, "failed to delete account metadata") + return fmt.Errorf("failed to delete account metadata: %w", err) } } } logCopy := log if err := sqlTx.InsertLog(ctx, &log); err != nil { - return errors.Wrap(err, "failed to insert log") + return fmt.Errorf("failed to insert log: %w", err) } if ctrl.ledger.HasFeature(ledger.FeatureHashLogs, "SYNC") { @@ -214,7 +214,7 @@ func (ctrl *DefaultController) CreateTransaction(ctx context.Context, parameters m, err := ctrl.machineFactory.Make(parameters.Input.Plain) if err != nil { - return nil, errors.Wrap(err, "failed to compile script") + return nil, fmt.Errorf("failed to compile script: %w", err) } output, err := forgeLog(ctx, ctrl.store, parameters, func(ctx context.Context, sqlTX TX, input RunScript) (*ledger.Log, *ledger.CreatedTransaction, error) { @@ -222,7 +222,7 @@ func (ctrl *DefaultController) CreateTransaction(ctx context.Context, parameters return m.Execute(ctx, newVmStoreAdapter(sqlTX), input.Vars) }) if err != nil { - return nil, nil, errors.Wrap(err, "failed to execute program") + return nil, nil, fmt.Errorf("failed to execute program: %w", err) } if len(result.Postings) == 0 { @@ -259,7 +259,7 @@ func (ctrl *DefaultController) CreateTransaction(ctx context.Context, parameters if len(result.AccountMetadata) > 0 { if err := sqlTX.UpdateAccountsMetadata(ctx, result.AccountMetadata); err != nil { - return nil, nil, errors.Wrapf(err, "updating metadata of account '%s'", Keys(result.AccountMetadata)) + return nil, nil, fmt.Errorf("updating metadata of account '%s': %w", Keys(result.AccountMetadata), err) } } @@ -296,7 +296,7 @@ func (ctrl *DefaultController) RevertTransaction(ctx context.Context, parameters balances, err := sqlTX.GetBalances(ctx, bq) if err != nil { - return nil, nil, errors.Wrap(err, "failed to get balances") + return nil, nil, fmt.Errorf("failed to get balances: %w", err) } reversedTx := originalTransaction.Reverse() @@ -332,7 +332,7 @@ func (ctrl *DefaultController) RevertTransaction(ctx context.Context, parameters err = sqlTX.CommitTransaction(ctx, &reversedTx) if err != nil { - return nil, nil, errors.Wrap(err, "failed to insert transaction") + return nil, nil, fmt.Errorf("failed to insert transaction: %w", err) } return pointer.For(ledger.NewRevertedTransactionLog(*originalTransaction, reversedTx)), &ledger.RevertedTransaction{ diff --git a/internal/controller/ledger/errors.go b/internal/controller/ledger/errors.go index 13ad00d62..682b2f299 100644 --- a/internal/controller/ledger/errors.go +++ b/internal/controller/ledger/errors.go @@ -8,7 +8,7 @@ import ( "github.com/formancehq/ledger/internal/machine" - "github.com/pkg/errors" + "errors" ) var ErrNotFound = postgres.ErrNotFound diff --git a/internal/controller/ledger/log_process.go b/internal/controller/ledger/log_process.go index 5cb1ee743..7be952873 100644 --- a/internal/controller/ledger/log_process.go +++ b/internal/controller/ledger/log_process.go @@ -2,12 +2,13 @@ package ledger import ( "context" + "errors" + "fmt" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/platform/postgres" "github.com/formancehq/go-libs/pointer" ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/tracing" - "github.com/pkg/errors" ) func runTx[INPUT, OUTPUT any](ctx context.Context, store Store, parameters Parameters[INPUT], fn func(ctx context.Context, sqlTX TX, input INPUT) (*ledger.Log, *OUTPUT, error)) (*OUTPUT, error) { @@ -27,7 +28,7 @@ func runTx[INPUT, OUTPUT any](ctx context.Context, store Store, parameters Param return nil, tx.InsertLog(ctx, log) }) if err != nil { - return false, errors.Wrap(err, "failed to insert log") + return false, fmt.Errorf("failed to insert log: %w", err) } logging.FromContext(ctx).Debugf("log inserted with id %d", log.ID) @@ -79,7 +80,7 @@ func forgeLog[INPUT, OUTPUT any](ctx context.Context, store Store, parameters Pa return pointer.For(log.Data.(OUTPUT)), nil default: - return nil, errors.Wrap(err, "unexpected error while forging log") + return nil, fmt.Errorf("unexpected error while forging log: %w", err) } } diff --git a/internal/controller/ledger/machine.go b/internal/controller/ledger/machine.go index af1647340..2ab94daa1 100644 --- a/internal/controller/ledger/machine.go +++ b/internal/controller/ledger/machine.go @@ -2,15 +2,16 @@ package ledger import ( "context" + "fmt" "github.com/formancehq/ledger/internal/machine" + "errors" "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/metadata" ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/machine/vm" "github.com/formancehq/ledger/internal/machine/vm/program" - "github.com/pkg/errors" ) type MachineResult struct { @@ -40,15 +41,15 @@ func (d *DefaultMachineAdapter) Execute(ctx context.Context, store vm.Store, var } if err := d.machine.SetVarsFromJSON(varsCopy); err != nil { - return nil, errors.Wrap(err, "failed to set vars from JSON") + return nil, fmt.Errorf("failed to set vars from JSON: %w", err) } err := d.machine.ResolveResources(ctx, store) if err != nil { - return nil, errors.Wrap(err, "failed to resolve resources") + return nil, fmt.Errorf("failed to resolve resources: %w", err) } if err := d.machine.ResolveBalances(ctx, store); err != nil { - return nil, errors.Wrap(err, "failed to resolve balances") + return nil, fmt.Errorf("failed to resolve balances: %w", err) } if err := d.machine.Execute(); err != nil { @@ -58,7 +59,7 @@ func (d *DefaultMachineAdapter) Execute(ctx context.Context, store vm.Store, var _ = errors.As(err, &errMetadataOverride) return nil, newErrMetadataOverride(errMetadataOverride.Key()) default: - return nil, errors.Wrap(err, "failed to execute machine") + return nil, fmt.Errorf("failed to execute machine: %w", err) } } diff --git a/internal/controller/ledger/stats.go b/internal/controller/ledger/stats.go index de0813dd0..46d9c92c4 100644 --- a/internal/controller/ledger/stats.go +++ b/internal/controller/ledger/stats.go @@ -2,8 +2,7 @@ package ledger import ( "context" - - "github.com/pkg/errors" + "fmt" ) type Stats struct { @@ -16,12 +15,12 @@ func (ctrl *DefaultController) GetStats(ctx context.Context) (Stats, error) { transactions, err := ctrl.store.CountTransactions(ctx, NewListTransactionsQuery(NewPaginatedQueryOptions(PITFilterWithVolumes{}))) if err != nil { - return stats, errors.Wrap(err, "counting transactions") + return stats, fmt.Errorf("counting transactions: %w", err) } accounts, err := ctrl.store.CountAccounts(ctx, NewListAccountsQuery(NewPaginatedQueryOptions(PITFilterWithVolumes{}))) if err != nil { - return stats, errors.Wrap(err, "counting accounts") + return stats, fmt.Errorf("counting accounts: %w", err) } return Stats{ diff --git a/internal/controller/system/errors.go b/internal/controller/system/errors.go index ac095ef99..50ae59067 100644 --- a/internal/controller/system/errors.go +++ b/internal/controller/system/errors.go @@ -1,7 +1,7 @@ package system import ( - "github.com/pkg/errors" + "errors" ) var ( diff --git a/internal/log.go b/internal/log.go index ff5d47801..d92b37917 100644 --- a/internal/log.go +++ b/internal/log.go @@ -13,8 +13,8 @@ import ( "github.com/formancehq/go-libs/time" + "errors" "github.com/formancehq/go-libs/metadata" - "github.com/pkg/errors" ) const ( diff --git a/internal/machine/errors.go b/internal/machine/errors.go index 78ae0e58a..47191a129 100644 --- a/internal/machine/errors.go +++ b/internal/machine/errors.go @@ -3,7 +3,7 @@ package machine import ( "fmt" - "github.com/pkg/errors" + "errors" ) var ( diff --git a/internal/machine/json.go b/internal/machine/json.go index 7f9387472..8c4d9c79e 100644 --- a/internal/machine/json.go +++ b/internal/machine/json.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/pkg/errors" + "errors" ) type ValueJSON struct { @@ -18,12 +18,12 @@ func NewValueFromString(typ Type, data string) (Value, error) { switch typ { case TypeAccount: if err := ValidateAccountAddress(AccountAddress(data)); err != nil { - return nil, errors.Wrapf(err, "value %s", data) + return nil, fmt.Errorf("value %s: %w", data, err) } value = AccountAddress(data) case TypeAsset: if err := ValidateAsset(Asset(data)); err != nil { - return nil, errors.Wrapf(err, "value %s", data) + return nil, fmt.Errorf("value %s: %v", data, err) } value = Asset(data) case TypeNumber: @@ -46,7 +46,7 @@ func NewValueFromString(typ Type, data string) (Value, error) { Amount: mi, } if err := ParseMonetary(mon); err != nil { - return nil, errors.Wrapf(err, "value %s", mon.String()) + return nil, fmt.Errorf("value %s: %w", mon.String(), err) } value = mon case TypePortion: diff --git a/internal/machine/monetary.go b/internal/machine/monetary.go index 1f0aabe55..ebd92f55d 100644 --- a/internal/machine/monetary.go +++ b/internal/machine/monetary.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - "github.com/pkg/errors" + "errors" ) type Monetary struct { @@ -28,13 +28,13 @@ var Zero = NewMonetaryInt(0) func ParseMonetary(mon Monetary) error { if err := ValidateAsset(mon.Asset); err != nil { - return errors.Wrapf(err, "asset '%s'", mon.Asset) + return fmt.Errorf("asset '%s': %w", mon.Asset, err) } if mon.Amount == nil { - return errors.Errorf("nil amount") + return fmt.Errorf("nil amount") } if mon.Amount.Ltz() { - return errors.Errorf("negative amount") + return fmt.Errorf("negative amount") } return nil } diff --git a/internal/machine/script/compiler/compiler.go b/internal/machine/script/compiler/compiler.go index aa8c09b2c..53800a837 100644 --- a/internal/machine/script/compiler/compiler.go +++ b/internal/machine/script/compiler/compiler.go @@ -7,10 +7,10 @@ import ( "github.com/formancehq/ledger/internal/machine" + "errors" "github.com/antlr/antlr4/runtime/Go/antlr" "github.com/formancehq/ledger/internal/machine/script/parser" "github.com/formancehq/ledger/internal/machine/vm/program" - "github.com/pkg/errors" ) type parseVisitor struct { @@ -526,8 +526,7 @@ func (p *parseVisitor) VisitVars(c *parser.VarListDeclContext) *CompileError { addr, err = p.AllocateResource(program.Variable{Typ: ty, Name: name}) if err != nil { return &CompileError{ - Msg: errors.Wrap(err, - "allocating variable resource").Error(), + Msg: fmt.Errorf("allocating variable resource: %w", err).Error(), } } p.varIdx[name] = *addr diff --git a/internal/machine/vm/machine.go b/internal/machine/vm/machine.go index e506668e2..0ef08ec26 100644 --- a/internal/machine/vm/machine.go +++ b/internal/machine/vm/machine.go @@ -18,9 +18,9 @@ import ( ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/machine" + "errors" "github.com/formancehq/ledger/internal/machine/vm/program" "github.com/logrusorgru/aurora" - "github.com/pkg/errors" ) type Machine struct { @@ -522,7 +522,7 @@ func (m *Machine) ResolveBalances(ctx context.Context, store Store) error { if len(balancesQuery) > 0 { balances, err := store.GetBalances(ctx, balancesQuery) if err != nil { - return errors.Wrap(err, "could not get balances") + return fmt.Errorf("could not get balances: %w", err) } for account, forAssets := range balances { diff --git a/internal/machine/vm/machine_test.go b/internal/machine/vm/machine_test.go index 3e657421a..f118b981a 100644 --- a/internal/machine/vm/machine_test.go +++ b/internal/machine/vm/machine_test.go @@ -11,11 +11,11 @@ import ( "github.com/formancehq/ledger/internal/machine" + "errors" "github.com/formancehq/go-libs/metadata" ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/machine/script/compiler" "github.com/formancehq/ledger/internal/machine/vm/program" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/machine/vm/program/program.go b/internal/machine/vm/program/program.go index 8a2a2f1c5..253839397 100644 --- a/internal/machine/vm/program/program.go +++ b/internal/machine/vm/program/program.go @@ -5,8 +5,6 @@ import ( "fmt" "github.com/formancehq/ledger/internal/machine" - - "github.com/pkg/errors" ) type Program struct { @@ -48,23 +46,23 @@ func (p *Program) ParseVariables(vars map[string]machine.Value) (map[string]mach switch val.GetType() { case machine.TypeAccount: if err := machine.ValidateAccountAddress(val.(machine.AccountAddress)); err != nil { - return nil, errors.Wrapf(err, "invalid variable $%s value '%s'", - variable.Name, string(val.(machine.AccountAddress))) + return nil, fmt.Errorf("invalid variable $%s value '%s': %w", + variable.Name, string(val.(machine.AccountAddress)), err) } case machine.TypeAsset: if err := machine.ValidateAsset(val.(machine.Asset)); err != nil { - return nil, errors.Wrapf(err, "invalid variable $%s value '%s'", - variable.Name, string(val.(machine.Asset))) + return nil, fmt.Errorf("invalid variable $%s value '%s': %w", + variable.Name, string(val.(machine.Asset)), err) } case machine.TypeMonetary: if err := machine.ParseMonetary(val.(machine.Monetary)); err != nil { - return nil, errors.Wrapf(err, "invalid variable $%s value '%s'", - variable.Name, val.(machine.Monetary).String()) + return nil, fmt.Errorf("invalid variable $%s value '%s': %w", + variable.Name, val.(machine.Monetary).String(), err) } case machine.TypePortion: if err := machine.ValidatePortionSpecific(val.(machine.Portion)); err != nil { - return nil, errors.Wrapf(err, "invalid variable $%s value '%s'", - variable.Name, val.(machine.Portion).String()) + return nil, fmt.Errorf("invalid variable $%s value '%s': %w", + variable.Name, val.(machine.Portion).String(), err) } case machine.TypeString: case machine.TypeNumber: diff --git a/internal/machine/vm/run.go b/internal/machine/vm/run.go index b64f39cad..b3b205f31 100644 --- a/internal/machine/vm/run.go +++ b/internal/machine/vm/run.go @@ -9,7 +9,6 @@ import ( "github.com/formancehq/go-libs/metadata" ledger "github.com/formancehq/ledger/internal" - "github.com/pkg/errors" ) type RunScript struct { @@ -53,7 +52,7 @@ type Result struct { func Run(m *Machine, script RunScript) (*Result, error) { err := m.Execute() if err != nil { - return nil, errors.Wrap(err, "script execution failed") + return nil, fmt.Errorf("script execution failed: %w", err) } result := Result{ diff --git a/internal/posting.go b/internal/posting.go index 904cb84b3..a6b7ef6e9 100644 --- a/internal/posting.go +++ b/internal/posting.go @@ -5,7 +5,7 @@ import ( "github.com/formancehq/ledger/pkg/assets" "math/big" - "github.com/pkg/errors" + "errors" ) type Posting struct { diff --git a/internal/storage/bucket/bucket.go b/internal/storage/bucket/bucket.go index c88bcd955..d18a3261d 100644 --- a/internal/storage/bucket/bucket.go +++ b/internal/storage/bucket/bucket.go @@ -7,8 +7,8 @@ import ( "github.com/formancehq/go-libs/platform/postgres" + "errors" "github.com/formancehq/go-libs/migrations" - "github.com/pkg/errors" "github.com/uptrace/bun" ) diff --git a/internal/storage/driver/driver.go b/internal/storage/driver/driver.go index 2d60d3848..7aa8fd644 100644 --- a/internal/storage/driver/driver.go +++ b/internal/storage/driver/driver.go @@ -3,6 +3,7 @@ package driver import ( "context" "database/sql" + "fmt" . "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/go-libs/platform/postgres" @@ -15,7 +16,6 @@ import ( ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/storage/bucket" ledgerstore "github.com/formancehq/ledger/internal/storage/ledger" - "github.com/pkg/errors" "github.com/uptrace/bun" "github.com/formancehq/go-libs/logging" @@ -42,25 +42,25 @@ func (d *Driver) CreateBucket(ctx context.Context, bucketName string) (*bucket.B isInitialized, err := b.IsInitialized(ctx) if err != nil { - return nil, errors.Wrap(err, "checking if bucket is initialized") + return nil, fmt.Errorf("checking if bucket is initialized: %w", err) } if isInitialized { isUpToDate, err := b.IsUpToDate(ctx) if err != nil { - return nil, errors.Wrap(err, "checking if bucket is up to date") + return nil, fmt.Errorf("checking if bucket is up to date: %w", err) } if !isUpToDate { return nil, systemcontroller.ErrNeedUpgradeBucket } } else { if err := bucket.Migrate(ctx, tx, bucketName); err != nil { - return nil, errors.Wrap(err, "migrating bucket") + return nil, fmt.Errorf("migrating bucket: %w", err) } } if err := tx.Commit(); err != nil { - return nil, errors.Wrap(err, "committing sql transaction to create bucket schema") + return nil, fmt.Errorf("committing sql transaction to create bucket schema: %w", err) } return b, nil @@ -70,20 +70,20 @@ func (d *Driver) createLedgerStore(ctx context.Context, db bun.IDB, ledger ledge tx, err := db.BeginTx(ctx, &sql.TxOptions{}) if err != nil { - return nil, errors.Wrap(err, "begin transaction") + return nil, fmt.Errorf("begin transaction: %w", err) } b := bucket.New(tx, ledger.Bucket) if err := b.Migrate(ctx); err != nil { - return nil, errors.Wrap(err, "migrating bucket") + return nil, fmt.Errorf("migrating bucket: %w", err) } if err := ledgerstore.Migrate(ctx, tx, ledger); err != nil { - return nil, errors.Wrap(err, "failed to migrate ledger store") + return nil, fmt.Errorf("failed to migrate ledger store: %w", err) } if err := tx.Commit(); err != nil { - return nil, errors.Wrap(err, "committing sql transaction to create ledger and schemas") + return nil, fmt.Errorf("committing sql transaction to create ledger and schemas: %w", err) } return ledgerstore.New(d.db, ledger), nil @@ -93,7 +93,7 @@ func (d *Driver) CreateLedger(ctx context.Context, l *ledger.Ledger) (*ledgersto tx, err := d.db.BeginTx(ctx, &sql.TxOptions{}) if err != nil { - return nil, errors.Wrap(err, "begin transaction") + return nil, fmt.Errorf("begin transaction: %w", err) } defer func() { _ = tx.Rollback() @@ -114,7 +114,7 @@ func (d *Driver) CreateLedger(ctx context.Context, l *ledger.Ledger) (*ledgersto affected, err := ret.RowsAffected() if err != nil { - return nil, errors.Wrap(err, "creating ledger") + return nil, fmt.Errorf("creating ledger: %w", err) } if affected == 0 { return nil, systemcontroller.ErrLedgerAlreadyExists @@ -126,7 +126,7 @@ func (d *Driver) CreateLedger(ctx context.Context, l *ledger.Ledger) (*ledgersto } if err := tx.Commit(); err != nil { - return nil, errors.Wrap(err, "committing sql transaction to create ledger schema") + return nil, fmt.Errorf("committing sql transaction to create ledger schema: %w", err) } return store, nil @@ -147,7 +147,11 @@ func (d *Driver) OpenLedger(ctx context.Context, name string) (*ledgerstore.Stor func (d *Driver) Initialize(ctx context.Context) error { logging.FromContext(ctx).Debugf("Initialize driver") - return errors.Wrap(Migrate(ctx, d.db), "migrating system store") + err := Migrate(ctx, d.db) + if err != nil { + return fmt.Errorf("migrating system store: %w", err) + } + return nil } func (d *Driver) UpdateLedgerMetadata(ctx context.Context, name string, m metadata.Metadata) error { diff --git a/internal/storage/ledger/accounts.go b/internal/storage/ledger/accounts.go index f62622bc2..51f2278d9 100644 --- a/internal/storage/ledger/accounts.go +++ b/internal/storage/ledger/accounts.go @@ -9,11 +9,11 @@ import ( . "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/ledger/internal/tracing" + "errors" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/go-libs/platform/postgres" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -94,7 +94,7 @@ func (s *Store) selectAccounts(date *time.Time, expandVolumes, expandEffectiveVo return nil }); err != nil { - return ret.Err(errors.Wrap(err, "failed to check filters")) + return ret.Err(fmt.Errorf("failed to check filters: %w", err)) } } @@ -189,7 +189,7 @@ func (s *Store) selectAccounts(date *time.Time, expandVolumes, expandEffectiveVo panic("unreachable") })) if err != nil { - return ret.Err(errors.Wrap(err, "evaluating filters")) + return ret.Err(fmt.Errorf("evaluating filters: %w", err)) } if len(args) > 0 { ret = ret.Where(where, args...) @@ -359,7 +359,7 @@ func (s *Store) UpsertAccount(ctx context.Context, account *ledger.Account) (boo return nil }) if err != nil && !errors.Is(err, rollbacked) { - return false, errors.Wrap(err, "upserting account") + return false, fmt.Errorf("upserting account: %w", err) } return upserted.Upserted, nil @@ -370,7 +370,7 @@ func (s *Store) UpsertAccount(ctx context.Context, account *ledger.Account) (boo ) }) if err != nil && !errors.Is(err, rollbacked) { - return false, errors.Wrap(err, "failed to upsert account") + return false, fmt.Errorf("failed to upsert account: %w", err) } else if upserted { logging.FromContext(ctx).Debugf("account upserted") } else { diff --git a/internal/storage/ledger/accounts_test.go b/internal/storage/ledger/accounts_test.go index d70633f43..f9ff9b6fd 100644 --- a/internal/storage/ledger/accounts_test.go +++ b/internal/storage/ledger/accounts_test.go @@ -7,9 +7,9 @@ import ( "math/big" "testing" + "errors" "github.com/formancehq/go-libs/pointer" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/formancehq/go-libs/time" diff --git a/internal/storage/ledger/balances.go b/internal/storage/ledger/balances.go index adf3bbce4..ed3686542 100644 --- a/internal/storage/ledger/balances.go +++ b/internal/storage/ledger/balances.go @@ -2,11 +2,11 @@ package ledger import ( "context" + "fmt" "math/big" "strings" "github.com/formancehq/go-libs/platform/postgres" - "github.com/pkg/errors" "github.com/formancehq/ledger/internal/tracing" @@ -140,7 +140,7 @@ func (s *Store) selectAccountWithAssetAndVolumes(date *time.Time, useInsertionDa } })) if err != nil { - return ret.Err(errors.Wrap(err, "building where clause")) + return ret.Err(fmt.Errorf("building where clause: %w", err)) } finalQuery = finalQuery.Where(where, args...) } diff --git a/internal/storage/ledger/errors.go b/internal/storage/ledger/errors.go index fdc970541..e8a53ec7f 100644 --- a/internal/storage/ledger/errors.go +++ b/internal/storage/ledger/errors.go @@ -1,7 +1,7 @@ package ledger import ( - "github.com/pkg/errors" + "errors" ) var ( diff --git a/internal/storage/ledger/logs.go b/internal/storage/ledger/logs.go index 298f0b706..fbd6a3a9d 100644 --- a/internal/storage/ledger/logs.go +++ b/internal/storage/ledger/logs.go @@ -8,13 +8,13 @@ import ( "fmt" "github.com/formancehq/ledger/internal/tracing" + "errors" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/platform/postgres" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/go-libs/query" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" ) // Log override ledger.Log to be able to properly read/write payload which is jsonb @@ -29,7 +29,7 @@ type Log struct { func (log Log) toCore() ledger.Log { payload, err := ledger.HydrateLog(log.Type, log.Data) if err != nil { - panic(errors.Wrap(err, "hydrating log data")) + panic(fmt.Errorf("hydrating log data: %w", err)) } log.Log.Data = payload @@ -63,7 +63,7 @@ func (s *Store) InsertLog(ctx context.Context, log *ledger.Log) error { Scan(ctx) if err != nil { if !errors.Is(err, sql.ErrNoRows) { - return errors.Wrap(err, "retrieving last log") + return fmt.Errorf("retrieving last log: %w", err) } log.ComputeHash(nil) } else { @@ -74,7 +74,7 @@ func (s *Store) InsertLog(ctx context.Context, log *ledger.Log) error { _, err := tracing.TraceWithLatency(ctx, "InsertLog", tracing.NoResult(func(ctx context.Context) error { data, err := json.Marshal(log.Data) if err != nil { - return errors.Wrap(err, "failed to marshal log data") + return fmt.Errorf("failed to marshal log data: %w", err) } _, err = s.db. @@ -96,7 +96,7 @@ func (s *Store) InsertLog(ctx context.Context, log *ledger.Log) error { return ledgercontroller.NewErrIdempotencyKeyConflict(log.IdempotencyKey) } default: - return errors.Wrap(err, "inserting log") + return fmt.Errorf("inserting log: %w", err) } } diff --git a/internal/storage/ledger/logs_test.go b/internal/storage/ledger/logs_test.go index a60322a9d..5bd839df6 100644 --- a/internal/storage/ledger/logs_test.go +++ b/internal/storage/ledger/logs_test.go @@ -9,8 +9,8 @@ import ( "math/big" "testing" + "errors" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/time" diff --git a/internal/storage/ledger/moves_test.go b/internal/storage/ledger/moves_test.go index c4cedf0f2..05656d923 100644 --- a/internal/storage/ledger/moves_test.go +++ b/internal/storage/ledger/moves_test.go @@ -10,6 +10,7 @@ import ( "math/rand" "testing" + "errors" "github.com/alitto/pond" "github.com/formancehq/go-libs/bun/bunpaginate" "github.com/formancehq/go-libs/logging" @@ -17,7 +18,6 @@ import ( "github.com/formancehq/go-libs/time" ledger "github.com/formancehq/ledger/internal" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/internal/storage/ledger/store.go b/internal/storage/ledger/store.go index 810c48c7b..909673477 100644 --- a/internal/storage/ledger/store.go +++ b/internal/storage/ledger/store.go @@ -8,12 +8,12 @@ import ( "github.com/formancehq/ledger/internal/tracing" + "errors" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/migrations" ledger "github.com/formancehq/ledger/internal" "github.com/formancehq/ledger/internal/storage/bucket" _ "github.com/jackc/pgx/v5/stdlib" - "github.com/pkg/errors" "github.com/uptrace/bun" ) @@ -52,7 +52,7 @@ func (s *Store) IsUpToDate(ctx context.Context) (bool, error) { return bucket.New(s.db, s.ledger.Bucket).IsUpToDate(ctx) }) if err != nil { - return false, errors.Wrap(err, "failed to check if bucket is up to date") + return false, fmt.Errorf("failed to check if bucket is up to date: %w", err) } if !bucketUpToDate { logging.FromContext(ctx).Errorf("bucket %s is not up to date", s.ledger.Bucket) diff --git a/internal/storage/ledger/transactions.go b/internal/storage/ledger/transactions.go index b2f3fab3a..ecb52e030 100644 --- a/internal/storage/ledger/transactions.go +++ b/internal/storage/ledger/transactions.go @@ -11,10 +11,10 @@ import ( "github.com/formancehq/ledger/internal/tracing" + "errors" . "github.com/formancehq/go-libs/collectionutils" "github.com/formancehq/go-libs/platform/postgres" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -255,19 +255,19 @@ func (s *Store) CommitTransaction(ctx context.Context, tx *ledger.Transaction) e Metadata: make(metadata.Metadata), }) if err != nil { - return errors.Wrap(err, "upserting account") + return fmt.Errorf("upserting account: %w", err) } } postCommitVolumes, err := s.UpdateVolumes(ctx, tx.VolumeUpdates()...) if err != nil { - return errors.Wrap(err, "failed to update balances") + return fmt.Errorf("failed to update balances: %w", err) } tx.PostCommitVolumes = postCommitVolumes.Copy() err = s.InsertTransaction(ctx, tx) if err != nil { - return errors.Wrap(err, "failed to insert transaction") + return fmt.Errorf("failed to insert transaction: %w", err) } if s.ledger.HasFeature(ledger.FeatureMovesHistory, "ON") { @@ -305,7 +305,7 @@ func (s *Store) CommitTransaction(ctx context.Context, tx *ledger.Transaction) e slices.Reverse(moves) if err := s.InsertMoves(ctx, moves...); err != nil { - return errors.Wrap(err, "failed to insert moves") + return fmt.Errorf("failed to insert moves: %w", err) } if s.ledger.HasFeature(ledger.FeatureMovesHistoryPostCommitEffectiveVolumes, "SYNC") { diff --git a/internal/storage/ledger/transactions_test.go b/internal/storage/ledger/transactions_test.go index 67b3a4844..8536ca971 100644 --- a/internal/storage/ledger/transactions_test.go +++ b/internal/storage/ledger/transactions_test.go @@ -13,7 +13,7 @@ import ( "github.com/formancehq/go-libs/time" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" + "errors" "github.com/formancehq/go-libs/logging" "github.com/formancehq/go-libs/pointer" diff --git a/internal/storage/ledger/volumes_test.go b/internal/storage/ledger/volumes_test.go index 99a10ad79..6495cf400 100644 --- a/internal/storage/ledger/volumes_test.go +++ b/internal/storage/ledger/volumes_test.go @@ -8,9 +8,9 @@ import ( "testing" libtime "time" + "errors" "github.com/formancehq/go-libs/platform/postgres" ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" - "github.com/pkg/errors" "github.com/formancehq/go-libs/time" diff --git a/pkg/testserver/matchers.go b/pkg/testserver/matchers.go index 1928441aa..7bb604ab3 100644 --- a/pkg/testserver/matchers.go +++ b/pkg/testserver/matchers.go @@ -3,6 +3,7 @@ package testserver import ( "context" "encoding/json" + "errors" "fmt" "github.com/formancehq/go-libs/pointer" "github.com/formancehq/go-libs/publish" @@ -12,7 +13,6 @@ import ( "github.com/nats-io/nats.go" . "github.com/onsi/gomega" "github.com/onsi/gomega/types" - "github.com/pkg/errors" "github.com/xeipuuv/gojsonschema" "math/big" "reflect" diff --git a/test/performance/env_core_test.go b/test/performance/env_core_test.go index f29572b36..28e008627 100644 --- a/test/performance/env_core_test.go +++ b/test/performance/env_core_test.go @@ -4,6 +4,7 @@ package performance_test import ( "context" + "fmt" systemstore "github.com/formancehq/ledger/internal/storage/driver" "testing" @@ -15,7 +16,6 @@ import ( ledgercontroller "github.com/formancehq/ledger/internal/controller/ledger" "github.com/formancehq/ledger/internal/storage/bucket" ledgerstore "github.com/formancehq/ledger/internal/storage/ledger" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "github.com/uptrace/bun" ) @@ -27,7 +27,11 @@ type CoreEnv struct { } func (e *CoreEnv) Stop(_ context.Context) error { - return errors.Wrap(e.bunDB.Close(), "failed to close database connection") + err := e.bunDB.Close() + if err != nil { + return fmt.Errorf("failed to close database connection: %w", err) + } + return nil } func (e *CoreEnv) Executor() TransactionExecutor { diff --git a/test/performance/env_remote_ledger_test.go b/test/performance/env_remote_ledger_test.go index c066448ff..9a873ae1d 100644 --- a/test/performance/env_remote_ledger_test.go +++ b/test/performance/env_remote_ledger_test.go @@ -4,6 +4,7 @@ package performance_test import ( "context" + "fmt" "net/http" "testing" @@ -13,7 +14,6 @@ import ( ledgerclient "github.com/formancehq/stack/ledger/client" "github.com/formancehq/stack/ledger/client/models/components" "github.com/formancehq/stack/ledger/client/models/operations" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) @@ -72,7 +72,7 @@ func (r *RemoteLedgerEnv) Executor() TransactionExecutor { }, }) if err != nil { - return nil, errors.Wrap(err, "creating transaction") + return nil, fmt.Errorf("creating transaction: %w", err) } return &ledger.Transaction{ diff --git a/test/performance/env_remote_stack_test.go b/test/performance/env_remote_stack_test.go index 164719048..1b5dd6cc3 100644 --- a/test/performance/env_remote_stack_test.go +++ b/test/performance/env_remote_stack_test.go @@ -4,6 +4,7 @@ package performance_test import ( "context" + "fmt" "net/http" "testing" @@ -13,7 +14,6 @@ import ( ledgerclient "github.com/formancehq/stack/ledger/client" "github.com/formancehq/stack/ledger/client/models/components" "github.com/formancehq/stack/ledger/client/models/operations" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) @@ -72,7 +72,7 @@ func (r *RemoteStackEnv) Executor() TransactionExecutor { Ledger: r.ledger.Name, }) if err != nil { - return nil, errors.Wrap(err, "creating transaction") + return nil, fmt.Errorf("creating transaction: %w", err) } return &ledger.Transaction{