From 36b9e9f296638c420d8b91ef2507483d30511f1b Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Sat, 28 Sep 2024 19:13:05 +0000 Subject: [PATCH] Use errors.Wrap() in repositories.go The API code unwraps errors wrapped by the errors.Wrap() function. It falls back to 500 error if it can't determine any other error type. Ultimately we need to migrate to the fmt.Errorf() pattern. But for now at least, we need to return proper errors. Any 500 error will not output details to the API. Neither will 401 for similar reasons. Signed-off-by: Gabriel Adrian Samfira --- runner/repositories.go | 6 +++--- runner/repositories_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runner/repositories.go b/runner/repositories.go index 4a76e570..5edff6ff 100644 --- a/runner/repositories.go +++ b/runner/repositories.go @@ -205,7 +205,7 @@ func (r *Runner) UpdateRepository(ctx context.Context, repoID string, param para poolMgr, err := r.poolManagerCtrl.GetRepoPoolManager(repo) if err != nil { - return params.Repository{}, fmt.Errorf("failed to get pool manager: %w", err) + return params.Repository{}, errors.Wrap(err, "getting pool manager") } repo.PoolManagerStatus = poolMgr.Status() @@ -219,7 +219,7 @@ func (r *Runner) CreateRepoPool(ctx context.Context, repoID string, param params createPoolParams, err := r.appendTagsToCreatePoolParams(param) if err != nil { - return params.Pool{}, fmt.Errorf("failed to append tags to create pool params: %w", err) + return params.Pool{}, errors.Wrap(err, "appending tags to create pool params") } if createPoolParams.RunnerBootstrapTimeout == 0 { @@ -233,7 +233,7 @@ func (r *Runner) CreateRepoPool(ctx context.Context, repoID string, param params pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams) if err != nil { - return params.Pool{}, fmt.Errorf("failed to create pool: %w", err) + return params.Pool{}, errors.Wrap(err, "creating pool") } return pool, nil diff --git a/runner/repositories_test.go b/runner/repositories_test.go index 9e55cbda..c1aa04b4 100644 --- a/runner/repositories_test.go +++ b/runner/repositories_test.go @@ -373,7 +373,7 @@ func (s *RepoTestSuite) TestUpdateRepositoryPoolMgrFailed() { _, err := s.Runner.UpdateRepository(s.Fixtures.AdminContext, s.Fixtures.StoreRepos["test-repo-1"].ID, s.Fixtures.UpdateRepoParams) s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T()) - s.Require().Equal(fmt.Sprintf("failed to get pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error()) + s.Require().Equal(fmt.Sprintf("getting pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error()) } func (s *RepoTestSuite) TestUpdateRepositoryCreateRepoPoolMgrFailed() { @@ -382,7 +382,7 @@ func (s *RepoTestSuite) TestUpdateRepositoryCreateRepoPoolMgrFailed() { _, err := s.Runner.UpdateRepository(s.Fixtures.AdminContext, s.Fixtures.StoreRepos["test-repo-1"].ID, s.Fixtures.UpdateRepoParams) s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T()) - s.Require().Equal(fmt.Sprintf("failed to get pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error()) + s.Require().Equal(fmt.Sprintf("getting pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error()) } func (s *RepoTestSuite) TestCreateRepoPool() { @@ -415,7 +415,7 @@ func (s *RepoTestSuite) TestCreateRepoPoolFetchPoolParamsFailed() { s.Fixtures.PoolMgrMock.AssertExpectations(s.T()) s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T()) - s.Require().Regexp("failed to append tags to create pool params: no such provider not-existent-provider-name", err.Error()) + s.Require().Regexp("appending tags to create pool params: no such provider not-existent-provider-name", err.Error()) } func (s *RepoTestSuite) TestGetRepoPoolByID() {