From b7566f724c531b9ae8eed702e19360c5cb866470 Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 22 Nov 2021 18:44:10 +0900 Subject: [PATCH 1/2] Fix the bug by the nested error --- internal/server/global/helper.go | 5 +---- pkg/e/code_test.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/server/global/helper.go b/internal/server/global/helper.go index 5e88308f..73d77af3 100644 --- a/internal/server/global/helper.go +++ b/internal/server/global/helper.go @@ -6,14 +6,11 @@ import ( "github.com/gitploy-io/gitploy/pkg/e" ) +// GetZapLogLevel return the warning level if the error is managed in the system. func GetZapLogLevel(err error) zapcore.Level { if !e.IsError(err) { return zapcore.ErrorLevel } - if err.(*e.Error).Code == e.ErrorCodeInternalError { - return zapcore.ErrorLevel - } - return zapcore.WarnLevel } diff --git a/pkg/e/code_test.go b/pkg/e/code_test.go index 67f9fbee..689aeaf8 100644 --- a/pkg/e/code_test.go +++ b/pkg/e/code_test.go @@ -1,6 +1,9 @@ package e -import "testing" +import ( + "fmt" + "testing" +) func Test_IsError(t *testing.T) { t.Run("Return true when the type of error is Error.", func(t *testing.T) { @@ -9,6 +12,13 @@ func Test_IsError(t *testing.T) { t.Fatalf("IsError = %v, wanted %v", ok, true) } }) + + t.Run("Return false when the type of error is not Error.", func(t *testing.T) { + err := fmt.Errorf("fmt.Error") + if ok := IsError(err); ok { + t.Fatalf("IsError = %v, wanted %v", ok, false) + } + }) } func Test_HasErrorCode(t *testing.T) { From 5779c72412a6969e34ebd23ec00955db2a2471fc Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 22 Nov 2021 19:20:32 +0900 Subject: [PATCH 2/2] Fix the bug from the constraint validation --- internal/pkg/store/repo.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/pkg/store/repo.go b/internal/pkg/store/repo.go index c83ff8f7..8f963f3e 100644 --- a/internal/pkg/store/repo.go +++ b/internal/pkg/store/repo.go @@ -220,11 +220,12 @@ func (s *Store) Activate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) { } func (s *Store) Deactivate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) { + // NOTE: Do not set the 'owner_id' zero value. + // It could make the constraint error. ret, err := s.c.Repo. UpdateOne(r). SetActive(false). SetWebhookID(0). - SetOwnerID(0). Save(ctx) if ent.IsValidationError(err) { return nil, e.NewErrorWithMessage(