Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Move error.go and util.go to common package

天舟bdccf91dfdc4
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index cecb7df922..2fc8b31c63 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -10,8 +10,8 @@ import (
"strings"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/server"
"github.com/bytebase/bytebase/store"
"github.com/spf13/cobra"
@@ -237,7 +237,7 @@ func initSetting(settingService api.SettingService) (*config, error) {
configCreate := &api.SettingCreate{
CreatorId: api.SYSTEM_BOT_ID,
Name: api.SettingAuthSecret,
- Value: bytebase.RandomString(SECRET_LENGTH),
+ Value: common.RandomString(SECRET_LENGTH),
Description: "Random string used to sign the JWT auth token.",
}
config, err := settingService.CreateSettingIfNotExist(context.Background(), configCreate)
diff --git a/error.go b/common/error.go
similarity index 99%
rename from error.go
rename to common/error.go
index b0a6fb5509..d6420951c5 100644
--- a/error.go
+++ b/common/error.go
@@ -1,4 +1,4 @@
-package bytebase
+package common
import (
"errors"
diff --git a/util.go b/common/util.go
similarity index 96%
rename from util.go
rename to common/util.go
index 0f57e61fbe..76c74a541d 100644
--- a/util.go
+++ b/common/util.go
@@ -1,4 +1,4 @@
-package bytebase
+package common
import (
"math/rand"
diff --git a/server/acl.go b/server/acl.go
index d8b1e48b18..c1a9006606 100644
--- a/server/acl.go
+++ b/server/acl.go
@@ -10,8 +10,8 @@ import (
"github.com/casbin/casbin/v2"
"go.uber.org/zap"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/labstack/echo/v4"
)
@@ -43,7 +43,7 @@ func ACLMiddleware(l *zap.Logger, s *Server, ce *casbin.Enforcer, next echo.Hand
}
member, err := s.MemberService.FindMember(context.Background(), memberFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User ID is not a member: %d", principalId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process authorize request.").SetInternal(err)
@@ -71,7 +71,7 @@ func ACLMiddleware(l *zap.Logger, s *Server, ce *casbin.Enforcer, next echo.Hand
}
activity, err := s.ActivityService.FindActivity(context.Background(), activityFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Activity ID not found: %d", activityId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process authorize request.").SetInternal(err)
@@ -92,7 +92,7 @@ func ACLMiddleware(l *zap.Logger, s *Server, ce *casbin.Enforcer, next echo.Hand
}
bookmark, err := s.BookmarkService.FindBookmark(context.Background(), bookmarkFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Bookmark ID not found: %d", bookmarkId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process authorize request.").SetInternal(err)
@@ -113,7 +113,7 @@ func ACLMiddleware(l *zap.Logger, s *Server, ce *casbin.Enforcer, next echo.Hand
}
inbox, err := s.InboxService.FindInbox(context.Background(), inboxFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Inbox ID not found: %d", inboxId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to process authorize request.").SetInternal(err)
diff --git a/server/activity.go b/server/activity.go
index 16b86301b4..5ae393d535 100644
--- a/server/activity.go
+++ b/server/activity.go
@@ -7,8 +7,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -29,7 +29,7 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {
}
issue, err := s.IssueService.FindIssue(context.Background(), issueFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to find issue ID for creating the comment: %d", activityCreate.ContainerId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID when creating the comment: %d", activityCreate.ContainerId)).SetInternal(err)
@@ -107,7 +107,7 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {
activity, err := s.ActivityService.PatchActivity(context.Background(), activityPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Activity ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch activity ID: %v", id)).SetInternal(err)
@@ -136,7 +136,7 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {
}
err = s.ActivityService.DeleteActivity(context.Background(), activityDelete)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Activity ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete activity ID: %v", id)).SetInternal(err)
diff --git a/server/auth.go b/server/auth.go
index 264f0d458c..512e6a95fc 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -6,8 +6,8 @@ import (
"fmt"
"net/http"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
"golang.org/x/crypto/bcrypt"
@@ -25,7 +25,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
}
user, err := s.PrincipalService.FindPrincipal(context.Background(), principalFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User not found: %s", login.Email))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to authenticate user").SetInternal(err)
@@ -36,7 +36,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
}
member, err := s.MemberService.FindMember(context.Background(), memberFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Member not found: %s", login.Email))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to authenticate user").SetInternal(err)
@@ -94,7 +94,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
user, err := s.PrincipalService.CreatePrincipal(context.Background(), principalCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Email already exists: %s", signup.Email))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to signup").SetInternal(err)
@@ -123,7 +123,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
member, err := s.MemberService.CreateMember(context.Background(), memberCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Member already exists: %s", signup.Email))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to signup").SetInternal(err)
diff --git a/server/backup_runner.go b/server/backup_runner.go
index 5e2ab5cb4d..f168885245 100644
--- a/server/backup_runner.go
+++ b/server/backup_runner.go
@@ -6,8 +6,8 @@ import (
"fmt"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -109,7 +109,7 @@ func (s *BackupRunner) scheduleBackupTask(database *api.Database, backupName str
}
backup, err := s.server.BackupService.CreateBackup(context.Background(), backupCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
// Automatic backup already exists.
return nil
}
diff --git a/server/bookmark.go b/server/bookmark.go
index f6cb2aebaa..272dbb2d9b 100644
--- a/server/bookmark.go
+++ b/server/bookmark.go
@@ -6,8 +6,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -23,7 +23,7 @@ func (s *Server) registerBookmarkRoutes(g *echo.Group) {
bookmark, err := s.BookmarkService.CreateBookmark(context.Background(), bookmarkCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Bookmark already exists: %s", bookmarkCreate.Link))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create bookmark").SetInternal(err)
@@ -75,7 +75,7 @@ func (s *Server) registerBookmarkRoutes(g *echo.Group) {
}
err = s.BookmarkService.DeleteBookmark(context.Background(), bookmarkDelete)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Bookmark ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete bookmark ID: %v", id)).SetInternal(err)
diff --git a/server/database.go b/server/database.go
index 83cc279c1f..a05e058c99 100644
--- a/server/database.go
+++ b/server/database.go
@@ -8,8 +8,8 @@ import (
"strconv"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -28,7 +28,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
database, err := s.DatabaseService.CreateDatabase(context.Background(), databaseCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Database name already exists: %s", databaseCreate.Name))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create database").SetInternal(err)
@@ -107,7 +107,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
database, err := s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -136,7 +136,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
database, err := s.DatabaseService.PatchDatabase(context.Background(), databasePatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch database ID: %v", id)).SetInternal(err)
@@ -164,7 +164,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
database, err := s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -217,7 +217,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
database, err := s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -277,7 +277,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
database, err := s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -299,7 +299,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
backup, err := s.BackupService.CreateBackup(context.Background(), backupCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Backup name already exists: %s", backupCreate.Name))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create backup").SetInternal(err)
@@ -367,7 +367,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
_, err = s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -411,7 +411,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
_, err = s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -440,7 +440,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
_, err = s.ComposeDatabaseByFind(context.Background(), databaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Database ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch database ID: %v", id)).SetInternal(err)
@@ -451,7 +451,7 @@ func (s *Server) registerDatabaseRoutes(g *echo.Group) {
}
backupSetting, err := s.BackupService.FindBackupSetting(context.Background(), backupSettingFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
// Returns the backup setting with UNKNOWN_ID to indicate the database has no backup
backupSetting = &api.BackupSetting{
ID: api.UNKNOWN_ID,
diff --git a/server/environment.go b/server/environment.go
index 98e30f3a83..9f659990da 100644
--- a/server/environment.go
+++ b/server/environment.go
@@ -7,8 +7,8 @@ import (
"reflect"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -24,7 +24,7 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {
environment, err := s.EnvironmentService.CreateEnvironment(context.Background(), environmentCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Environment name already exists: %s", environmentCreate.Name))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create environment").SetInternal(err)
@@ -81,7 +81,7 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {
environment, err := s.EnvironmentService.PatchEnvironment(context.Background(), environmentPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch environment ID: %v", id)).SetInternal(err)
@@ -109,7 +109,7 @@ func (s *Server) registerEnvironmentRoutes(g *echo.Group) {
environmentPatch.UpdaterId = c.Get(GetPrincipalIdContextKey()).(int)
_, err = s.EnvironmentService.PatchEnvironment(context.Background(), environmentPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Environment ID not found: %d", environmentPatch.ID))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch environment ID: %v", environmentPatch.ID)).SetInternal(err)
diff --git a/server/inbox.go b/server/inbox.go
index be6d9a2183..cc03afe2d0 100644
--- a/server/inbox.go
+++ b/server/inbox.go
@@ -6,8 +6,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -82,7 +82,7 @@ func (s *Server) registerInboxRoutes(g *echo.Group) {
inbox, err := s.InboxService.PatchInbox(context.Background(), inboxPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Inbox ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch inbox ID: %v", id)).SetInternal(err)
diff --git a/server/instance.go b/server/instance.go
index dbf51f27d7..c6235c2f64 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -6,8 +6,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/db"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
@@ -25,7 +25,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
instance, err := s.InstanceService.CreateInstance(context.Background(), instanceCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Instance name already exists: %s", instanceCreate.Name))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create instance").SetInternal(err)
@@ -99,7 +99,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
instance, err := s.ComposeInstanceById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
@@ -130,7 +130,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
if instancePatch.RowStatus != nil || instancePatch.Name != nil || instancePatch.ExternalLink != nil || instancePatch.Host != nil || instancePatch.Port != nil {
instance, err = s.InstanceService.PatchInstance(context.Background(), instancePatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch instance ID: %v", id)).SetInternal(err)
@@ -143,7 +143,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
}
instance, err = s.InstanceService.FindInstance(context.Background(), instanceFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
@@ -211,7 +211,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
instance, err := s.ComposeInstanceById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
@@ -256,7 +256,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
instance, err := s.ComposeInstanceById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
@@ -308,7 +308,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
instance, err := s.ComposeInstanceById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", id)).SetInternal(err)
@@ -445,5 +445,5 @@ func (s *Server) FindInstanceAdminPasswordById(ctx context.Context, instanceId i
return dataSource.Password, nil
}
}
- return "", &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("missing admin password for instance: %d", instanceId)}
+ return "", &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("missing admin password for instance: %d", instanceId)}
}
diff --git a/server/issue.go b/server/issue.go
index ef03350dc6..e9f8ddd71d 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -8,8 +8,8 @@ import (
"strconv"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -102,7 +102,7 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
issue, err := s.ComposeIssueById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Issue ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID: %v", id)).SetInternal(err)
@@ -134,7 +134,7 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
}
issue, err := s.IssueService.FindIssue(context.Background(), issueFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to find issue ID to update: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID when updating issue: %v", id)).SetInternal(err)
@@ -226,7 +226,7 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
issue, err := s.ComposeIssueById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Issue ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID: %v", id)).SetInternal(err)
@@ -234,9 +234,9 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
updatedIssue, err := s.ChangeIssueStatus(context.Background(), issue, issueStatusPatch.Status, issueStatusPatch.UpdaterId, issueStatusPatch.Comment)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound).SetInternal(err)
- } else if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ } else if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict).SetInternal(err)
}
return echo.NewHTTPError(http.StatusInternalServerError).SetInternal(err)
@@ -458,7 +458,7 @@ func (s *Server) ChangeIssueStatus(ctx context.Context, issue *api.Issue, newSta
for _, stage := range issue.Pipeline.StageList {
for _, task := range stage.TaskList {
if task.Status != api.TaskDone {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("failed to resolve issue: %v, task %v has not finished", issue.Name, task.Name)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("failed to resolve issue: %v, task %v has not finished", issue.Name, task.Name)}
}
}
}
@@ -495,7 +495,7 @@ func (s *Server) ChangeIssueStatus(ctx context.Context, issue *api.Issue, newSta
}
updatedIssue, err := s.IssueService.PatchIssue(context.Background(), issuePatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return nil, fmt.Errorf("failed to update issue status: %v, error: %w", issue.Name, err)
}
return nil, fmt.Errorf("failed update issue status: %v, error: %w", issue.Name, err)
diff --git a/server/issue_subscriber.go b/server/issue_subscriber.go
index 2286aca507..1bb485056c 100644
--- a/server/issue_subscriber.go
+++ b/server/issue_subscriber.go
@@ -6,8 +6,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -28,7 +28,7 @@ func (s *Server) registerIssueSubscriberRoutes(g *echo.Group) {
issueSubscriber, err := s.IssueSubscriberService.CreateIssueSubscriber(context.Background(), issueSubscriberCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Subscriber %d already exists in issue %d", issueSubscriberCreate.SubscriberId, issueSubscriberCreate.IssueId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to add subscriber %d to issue %d", issueSubscriberCreate.SubscriberId, issueSubscriberCreate.IssueId)).SetInternal(err)
@@ -89,7 +89,7 @@ func (s *Server) registerIssueSubscriberRoutes(g *echo.Group) {
}
err = s.IssueSubscriberService.DeleteIssueSubscriber(context.Background(), issueSubscriberDelete)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Subscriber %d not found in issue %d", subscriberId, issueId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete subscriber %d from issue %d", subscriberId, issueId)).SetInternal(err)
diff --git a/server/jwt.go b/server/jwt.go
index 47b3440bd9..162027dabc 100644
--- a/server/jwt.go
+++ b/server/jwt.go
@@ -9,8 +9,8 @@ import (
"strings"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
@@ -220,7 +220,7 @@ func JWTMiddleware(l *zap.Logger, p api.PrincipalService, next echo.HandlerFunc,
}
user, err := p.FindPrincipal(context.Background(), principalFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Failed to find user ID: %d", principalId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Server error to find user ID: %d", principalId)).SetInternal(err)
diff --git a/server/member.go b/server/member.go
index 16f9146305..7849f9c59b 100644
--- a/server/member.go
+++ b/server/member.go
@@ -7,8 +7,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -24,7 +24,7 @@ func (s *Server) registerMemberRoutes(g *echo.Group) {
member, err := s.MemberService.CreateMember(context.Background(), memberCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Member for user ID already exists: %d", memberCreate.PrincipalId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create member").SetInternal(err)
@@ -37,7 +37,7 @@ func (s *Server) registerMemberRoutes(g *echo.Group) {
}
user, err := s.PrincipalService.FindPrincipal(context.Background(), principalFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Failed to find user ID: %d", member.PrincipalId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Server error to find user ID: %d", member.PrincipalId)).SetInternal(err)
@@ -108,7 +108,7 @@ func (s *Server) registerMemberRoutes(g *echo.Group) {
}
member, err := s.MemberService.FindMember(context.Background(), memberFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Failed to find member ID: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Server error to find member ID: %d", id)).SetInternal(err)
@@ -124,7 +124,7 @@ func (s *Server) registerMemberRoutes(g *echo.Group) {
updatedMember, err := s.MemberService.PatchMember(context.Background(), memberPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Member ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch member ID: %v", id)).SetInternal(err)
@@ -137,7 +137,7 @@ func (s *Server) registerMemberRoutes(g *echo.Group) {
}
user, err := s.PrincipalService.FindPrincipal(context.Background(), principalFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Failed to find user ID: %d", updatedMember.PrincipalId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Server error to find user ID: %d", updatedMember.PrincipalId)).SetInternal(err)
diff --git a/server/principal.go b/server/principal.go
index 992a5aa763..b7a8faa79c 100644
--- a/server/principal.go
+++ b/server/principal.go
@@ -6,8 +6,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
@@ -31,7 +31,7 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
principal, err := s.PrincipalService.CreatePrincipal(context.Background(), principalCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, "User already exists")
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create principal").SetInternal(err)
@@ -57,7 +57,7 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
if err := s.ComposePrincipalRole(context.Background(), principal); err != nil {
// Normally this should not happen since we create the member together with the principal
// and we don't allow deleting the member. Just in case.
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
s.l.Error("Principal has not been assigned a role. Skip",
zap.Int("id", principal.ID),
zap.String("name", principal.Name),
@@ -84,7 +84,7 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
principal, err := s.ComposePrincipalById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("User ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch principal ID: %v", id)).SetInternal(err)
@@ -121,7 +121,7 @@ func (s *Server) registerPrincipalRoutes(g *echo.Group) {
principal, err := s.PrincipalService.PatchPrincipal(context.Background(), principalPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("User ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch principal ID: %v", id)).SetInternal(err)
diff --git a/server/project.go b/server/project.go
index 879cbd5c1d..3aa5752951 100644
--- a/server/project.go
+++ b/server/project.go
@@ -9,8 +9,8 @@ import (
"strconv"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/external/gitlab"
"github.com/google/jsonapi"
"github.com/google/uuid"
@@ -27,7 +27,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
projectCreate.CreatorId = c.Get(GetPrincipalIdContextKey()).(int)
project, err := s.ProjectService.CreateProject(context.Background(), projectCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Project name already exists: %s", projectCreate.Name))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create project").SetInternal(err)
@@ -95,7 +95,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
project, err := s.ComposeProjectlById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project ID: %v", id)).SetInternal(err)
@@ -124,7 +124,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
project, err := s.ProjectService.PatchProject(context.Background(), projectPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to patch project ID: %v", id)).SetInternal(err)
@@ -153,7 +153,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
}
vcs, err := s.VCSService.FindVCS(context.Background(), vcsFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("VCS ID not found: %d", repositoryCreate.VCSId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find VCS for creating repository: %d", repositoryCreate.VCSId)).SetInternal(err)
@@ -161,7 +161,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
repositoryCreate.WebhookURLHost = fmt.Sprintf("%s:%d", s.host, s.port)
repositoryCreate.WebhookEndpointId = uuid.New().String()
- repositoryCreate.WebhookSecretToken = bytebase.RandomString(gitlab.SECRET_TOKEN_LENGTH)
+ repositoryCreate.WebhookSecretToken = common.RandomString(gitlab.SECRET_TOKEN_LENGTH)
switch vcs.Type {
case "GITLAB_SELF_HOST":
webhookPost := gitlab.WebhookPost{
@@ -203,7 +203,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
repositoryCreate.BaseDirectory = strings.Trim(repositoryCreate.BaseDirectory, "/")
repository, err := s.RepositoryService.CreateRepository(context.Background(), repositoryCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Project %d has already linked repository", repositoryCreate.ProjectId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to link project repository").SetInternal(err)
diff --git a/server/project_member.go b/server/project_member.go
index 6405aa60b9..97f1269503 100644
--- a/server/project_member.go
+++ b/server/project_member.go
@@ -6,8 +6,8 @@ import (
"net/http"
"strconv"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -29,7 +29,7 @@ func (s *Server) registerProjectMemberRoutes(g *echo.Group) {
projectMember, err := s.ProjectMemberService.CreateProjectMember(context.Background(), projectMemberCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, "User is already a project member")
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create project member").SetInternal(err)
@@ -67,7 +67,7 @@ func (s *Server) registerProjectMemberRoutes(g *echo.Group) {
projectMember, err := s.ProjectMemberService.PatchProjectMember(context.Background(), projectMemberPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project member ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to change project membership ID: %v", id)).SetInternal(err)
@@ -101,7 +101,7 @@ func (s *Server) registerProjectMemberRoutes(g *echo.Group) {
}
err = s.ProjectMemberService.DeleteProjectMember(context.Background(), projectMemberDelete)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project member ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete project member ID: %v", id)).SetInternal(err)
diff --git a/server/project_webhook.go b/server/project_webhook.go
index 4db0004d95..089f4a8f7c 100644
--- a/server/project_webhook.go
+++ b/server/project_webhook.go
@@ -7,8 +7,8 @@ import (
"strconv"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/webhook"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
@@ -58,7 +58,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
hook, err := s.ProjectWebhookService.CreateProjectWebhook(context.Background(), hookCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Webhook url already exists in the project: %s", hookCreate.URL))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create project webhook").SetInternal(err)
@@ -91,7 +91,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
}
hook, err := s.ProjectWebhookService.FindProjectWebhook(context.Background(), find)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project webhook ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project webhook ID: %v", id)).SetInternal(err)
@@ -129,10 +129,10 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
hook, err := s.ProjectWebhookService.PatchProjectWebhook(context.Background(), hookPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project webhook ID not found: %d", id))
}
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Hook url already exists in the project: %s", *hookPatch.URL))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to change project webhook ID: %v", id)).SetInternal(err)
@@ -166,7 +166,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
}
err = s.ProjectWebhookService.DeleteProjectWebhook(context.Background(), hookDelete)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project webhook ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete project webhook ID: %v", id)).SetInternal(err)
@@ -188,7 +188,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
}
project, err := s.ProjectService.FindProject(context.Background(), projectFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project ID not found: %d", projectId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project ID: %v", projectId)).SetInternal(err)
@@ -204,7 +204,7 @@ func (s *Server) registerProjectWebhookRoutes(g *echo.Group) {
}
hook, err := s.ProjectWebhookService.FindProjectWebhook(context.Background(), find)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Project webhook ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch project webhook ID: %v", id)).SetInternal(err)
diff --git a/server/setting.go b/server/setting.go
index 964788998a..17fc3e7123 100644
--- a/server/setting.go
+++ b/server/setting.go
@@ -5,8 +5,8 @@ import (
"fmt"
"net/http"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -58,7 +58,7 @@ func (s *Server) registerSettingRoutes(g *echo.Group) {
setting, err := s.SettingService.PatchSetting(context.Background(), settingPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Setting name not found: %s", settingPatch.Name))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update setting: %v", settingPatch.Name)).SetInternal(err)
diff --git a/server/sql.go b/server/sql.go
index 5c1f917a1e..76b60d7622 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -6,8 +6,8 @@ import (
"net/http"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/db"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
@@ -78,7 +78,7 @@ func (s *Server) registerSqlRoutes(g *echo.Group) {
instance, err := s.ComposeInstanceById(context.Background(), sync.InstanceId)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", sync.InstanceId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch instance ID: %v", sync.InstanceId)).SetInternal(err)
@@ -124,7 +124,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
var createTable = func(database *api.Database, tableCreate *api.TableCreate) (*api.Table, error) {
createTable, err := s.TableService.CreateTable(context.Background(), tableCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return nil, fmt.Errorf("failed to sync table for instance: %s, database: %s. Table name already exists: %s", instance.Name, database.Name, tableCreate.Name)
}
return nil, fmt.Errorf("failed to sync table for instance: %s, database: %s. Failed to import new table: %s. Error %w", instance.Name, database.Name, tableCreate.Name, err)
@@ -135,7 +135,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
var createColumn = func(database *api.Database, table *api.Table, columnCreate *api.ColumnCreate) error {
_, err := s.ColumnService.CreateColumn(context.Background(), columnCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Column name already exists: %s", instance.Name, database.Name, table.Name, columnCreate.Name)
}
return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Failed to import new column: %s. Error %w", instance.Name, database.Name, table.Name, columnCreate.Name, err)
@@ -146,7 +146,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
var createIndex = func(database *api.Database, table *api.Table, indexCreate *api.IndexCreate) error {
_, err := s.IndexService.CreateIndex(context.Background(), indexCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. index and expression already exists: %s(%s)", instance.Name, database.Name, table.Name, indexCreate.Name, indexCreate.Expression)
}
return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Failed to import new index and expression: %s(%s). Error %w", instance.Name, database.Name, table.Name, indexCreate.Name, indexCreate.Expression, err)
@@ -232,7 +232,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
database, err := s.DatabaseService.PatchDatabase(context.Background(), databasePatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return fmt.Errorf("failed to sync database for instance: %s. Database not found: %s", instance.Name, database.Name)
}
return fmt.Errorf("failed to sync database for instance: %s. Failed to update database: %s. Error %w", instance.Name, database.Name, err)
@@ -247,7 +247,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
storedTable, err := s.TableService.FindTable(context.Background(), tableFind)
var upsertedTable *api.Table
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
tableCreate := &api.TableCreate{
CreatorId: api.SYSTEM_BOT_ID,
DatabaseId: database.ID,
@@ -278,7 +278,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
upsertedTable, err = s.TableService.PatchTable(context.Background(), tablePatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return fmt.Errorf("failed to sync table for instance: %s, database: %s. Table not found: %s", instance.Name, database.Name, storedTable.Name)
}
return fmt.Errorf("failed to sync table for instance: %s, database: %s. Failed to update table: %s. Error %w", instance.Name, database.Name, storedTable.Name, err)
@@ -294,7 +294,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
storedColumn, err := s.ColumnService.FindColumn(context.Background(), columnFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
columnCreate := &api.ColumnCreate{
CreatorId: api.SYSTEM_BOT_ID,
DatabaseId: database.ID,
@@ -323,7 +323,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
_, err := s.ColumnService.PatchColumn(context.Background(), columnPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Column not found: %s", instance.Name, database.Name, upsertedTable.Name, storedColumn.Name)
}
return fmt.Errorf("failed to sync column for instance: %s, database: %s, table: %s. Failed to update column: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, storedColumn.Name, err)
@@ -341,7 +341,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
storedIndex, err := s.IndexService.FindIndex(context.Background(), indexFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
indexCreate := &api.IndexCreate{
CreatorId: api.SYSTEM_BOT_ID,
DatabaseId: database.ID,
@@ -369,7 +369,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
_, err := s.IndexService.PatchIndex(context.Background(), indexPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Index not found: %s", instance.Name, database.Name, upsertedTable.Name, storedIndex.Name)
}
return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Failed to update index: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, storedIndex.Name, err)
@@ -392,7 +392,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
database, err := s.DatabaseService.CreateDatabase(context.Background(), databaseCreate)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ECONFLICT {
+ if common.ErrorCode(err) == common.ECONFLICT {
return fmt.Errorf("failed to sync database for instance: %s. Database name already exists: %s", instance.Name, databaseCreate.Name)
}
return fmt.Errorf("failed to sync database for instance: %s. Failed to import new database: %s. Error %w", instance.Name, databaseCreate.Name, err)
@@ -428,7 +428,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
_, err := s.ColumnService.FindColumn(context.Background(), columnFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
columnCreate := &api.ColumnCreate{
CreatorId: api.SYSTEM_BOT_ID,
DatabaseId: database.ID,
@@ -461,7 +461,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
_, err := s.IndexService.FindIndex(context.Background(), indexFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
indexCreate := &api.IndexCreate{
CreatorId: api.SYSTEM_BOT_ID,
DatabaseId: database.ID,
@@ -506,7 +506,7 @@ func (s *Server) SyncSchema(instance *api.Instance) (rs *api.SqlResultSet) {
}
database, err := s.DatabaseService.PatchDatabase(context.Background(), databasePatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return fmt.Errorf("failed to sync database for instance: %s. Database not found: %s", instance.Name, database.Name)
}
return fmt.Errorf("failed to sync database for instance: %s. Failed to update database: %s. Error: %w", instance.Name, database.Name, err)
diff --git a/server/task.go b/server/task.go
index 56e11e7ed2..dbfbf72077 100644
--- a/server/task.go
+++ b/server/task.go
@@ -8,8 +8,8 @@ import (
"strconv"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
@@ -46,7 +46,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
}
task, err := s.TaskService.FindTask(context.Background(), taskFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskId))
}
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task status").SetInternal(err)
@@ -54,8 +54,8 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
updatedTask, err := s.ChangeTaskStatusWithPatch(context.Background(), task, taskStatusPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.EINVALID {
- return echo.NewHTTPError(http.StatusBadRequest, bytebase.ErrorMessage(err))
+ if common.ErrorCode(err) == common.EINVALID {
+ return echo.NewHTTPError(http.StatusBadRequest, common.ErrorMessage(err))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update task \"%v\" status", task.Name)).SetInternal(err)
}
@@ -179,8 +179,8 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
}
if !allowTransition {
- return nil, &bytebase.Error{
- Code: bytebase.EINVALID,
+ return nil, &common.Error{
+ Code: common.EINVALID,
Message: fmt.Sprintf("Invalid task status transition from %v to %v. Applicable transition(s) %v", task.Status, taskStatusPatch.Status, applicableTaskStatusTransition[task.Status])}
}
@@ -198,7 +198,7 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
issue, err := s.IssueService.FindIssue(ctx, issueFind)
if err != nil {
// Not all pipelines belong to an issue, so it's OK if ENOTFOUND
- if bytebase.ErrorCode(err) != bytebase.ENOTFOUND {
+ if common.ErrorCode(err) != common.ENOTFOUND {
return nil, fmt.Errorf("failed to fetch containing issue after changing the task status: %v, err: %w", task.Name, err)
}
}
diff --git a/server/task_executor_database_restore.go b/server/task_executor_database_restore.go
index 229e4e134a..f0a816b349 100644
--- a/server/task_executor_database_restore.go
+++ b/server/task_executor_database_restore.go
@@ -11,10 +11,10 @@ import (
"strings"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/bin/bb/connect"
"github.com/bytebase/bytebase/bin/bb/restore/mysqlrestore"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/db"
"go.uber.org/zap"
)
@@ -73,7 +73,7 @@ func (exec *DatabaseRestoreTaskExecutor) RunOnce(ctx context.Context, server *Se
}
targetDatabase, err := server.ComposeDatabaseByFind(context.Background(), targetDatabaseFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return true, "", fmt.Errorf("target database %q not found in instance %q: %w", targetDatabase.Name, task.Instance.Name, err)
}
return true, "", fmt.Errorf("failed to find target database %q in instance %q: %w", targetDatabase.Name, task.Instance.Name, err)
@@ -148,7 +148,7 @@ func branchMigrationHistoryIfNeeded(ctx context.Context, server *Server, sourceD
issue, err := server.IssueService.FindIssue(ctx, issueFind)
if err != nil {
// Not all pipelines belong to an issue, so it's OK if ENOTFOUND
- if bytebase.ErrorCode(err) != bytebase.ENOTFOUND {
+ if common.ErrorCode(err) != common.ENOTFOUND {
return fmt.Errorf("failed to fetch containing issue when creating the migration history: %v, err: %w", task.Name, err)
}
}
diff --git a/server/vcs.go b/server/vcs.go
index 92d491b960..77399dd4d5 100644
--- a/server/vcs.go
+++ b/server/vcs.go
@@ -7,8 +7,8 @@ import (
"strconv"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/external/gitlab"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
@@ -70,7 +70,7 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {
vcs, err := s.ComposeVCSById(context.Background(), id)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("VCS ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch vcs ID: %v", id)).SetInternal(err)
@@ -99,7 +99,7 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {
vcs, err := s.VCSService.PatchVCS(context.Background(), vcsPatch)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("VCS ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to change VCS ID: %v", id)).SetInternal(err)
@@ -128,7 +128,7 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {
}
err = s.VCSService.DeleteVCS(context.Background(), vcsDelete)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("VCS ID not found: %d", id))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete VCS ID: %v", id)).SetInternal(err)
diff --git a/server/webhook.go b/server/webhook.go
index a6a47b6faa..340d27e4b7 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -12,7 +12,6 @@ import (
"strings"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/db"
@@ -49,7 +48,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
}
repository, err := s.RepositoryService.FindRepository(context.Background(), repositoryFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Endpoint not found: %v", webhookEndpointId))
}
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to respond webhook event for endpoint: %v", webhookEndpointId)).SetInternal(err)
diff --git a/store/activity.go b/store/activity.go
index 61d1c6c4c6..05ad7a75ef 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *ActivityService) FindActivity(ctx context.Context, find *api.ActivityFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("activity not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("activity not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
@@ -277,7 +277,7 @@ func patchActivity(ctx context.Context, tx *Tx, patch *api.ActivityPatch) (*api.
return &activity, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("activity ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("activity ID not found: %d", patch.ID)}
}
// deleteActivity permanently deletes a activity by ID.
@@ -290,7 +290,7 @@ func deleteActivity(ctx context.Context, tx *Tx, delete *api.ActivityDelete) err
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("activity ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("activity ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/backup.go b/store/backup.go
index c04044cfcc..c52e5a3326 100644
--- a/store/backup.go
+++ b/store/backup.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -59,9 +59,9 @@ func (s *BackupService) FindBackup(ctx context.Context, find *api.BackupFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("backup not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("backup not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d backups with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d backups with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
@@ -275,7 +275,7 @@ func (s *BackupService) patchBackup(ctx context.Context, tx *Tx, patch *api.Back
return &backup, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("backup ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("backup ID not found: %d", patch.ID)}
}
// FindBackupSetting finds the backup setting for a database.
@@ -292,9 +292,9 @@ func (s *BackupService) FindBackupSetting(ctx context.Context, find *api.BackupS
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("backup setting not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("backup setting not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d backup settings with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d backup settings with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
diff --git a/store/bookmark.go b/store/bookmark.go
index c5a0024bbd..0bc217e19d 100644
--- a/store/bookmark.go
+++ b/store/bookmark.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *BookmarkService) FindBookmark(ctx context.Context, find *api.BookmarkFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("bookmark not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("bookmark not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
@@ -207,7 +207,7 @@ func deleteBookmark(ctx context.Context, tx *Tx, delete *api.BookmarkDelete) err
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("bookmark ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("bookmark ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/column.go b/store/column.go
index c240b677b5..0852cde5f7 100644
--- a/store/column.go
+++ b/store/column.go
@@ -6,8 +6,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -76,9 +76,9 @@ func (s *ColumnService) FindColumn(ctx context.Context, find *api.ColumnFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("column not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("column not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d columns with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d columns with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -329,5 +329,5 @@ func (s *ColumnService) patchColumn(ctx context.Context, tx *Tx, patch *api.Colu
return &column, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("column ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("column ID not found: %d", patch.ID)}
}
diff --git a/store/data_source.go b/store/data_source.go
index 6a3da61d29..59bc6a62af 100644
--- a/store/data_source.go
+++ b/store/data_source.go
@@ -6,8 +6,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -80,9 +80,9 @@ func (s *DataSourceService) FindDataSource(ctx context.Context, find *api.DataSo
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("data source not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("data source not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d data sources with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d data sources with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -272,5 +272,5 @@ func (s *DataSourceService) patchDataSource(ctx context.Context, tx *Tx, patch *
return &dataSource, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("dataSource ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("dataSource ID not found: %d", patch.ID)}
}
diff --git a/store/database.go b/store/database.go
index 6b874b1fe0..ba2546c461 100644
--- a/store/database.go
+++ b/store/database.go
@@ -6,8 +6,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -114,9 +114,9 @@ func (s *DatabaseService) FindDatabase(ctx context.Context, find *api.DatabaseFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("database not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("database not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d databases with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d databases with filter %+v, expect 1. ", len(list), find)}
}
if err := s.cache.UpsertCache(api.DatabaseCache, list[0].ID, list[0]); err != nil {
@@ -328,5 +328,5 @@ func (s *DatabaseService) patchDatabase(ctx context.Context, tx *Tx, patch *api.
return &database, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("database ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("database ID not found: %d", patch.ID)}
}
diff --git a/store/environment.go b/store/environment.go
index cfb8b8e4d1..eb5b80aa11 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -100,9 +100,9 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("environment not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d environments with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d environments with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.EnvironmentCache, list[0].ID, list[0]); err != nil {
@@ -311,5 +311,5 @@ func (s *EnvironmentService) patchEnvironment(ctx context.Context, tx *Tx, patch
return &environment, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("environment ID not found: %d", patch.ID)}
}
diff --git a/store/inbox.go b/store/inbox.go
index 7cd732a418..c0f9b6431e 100644
--- a/store/inbox.go
+++ b/store/inbox.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -77,9 +77,9 @@ func (s *InboxService) FindInbox(ctx context.Context, find *api.InboxFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("inbox not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("inbox not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d inboxes with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d inboxes with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -315,5 +315,5 @@ func (s *InboxService) patchInbox(ctx context.Context, tx *Tx, patch *api.InboxP
return &inbox, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("inbox ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("inbox ID not found: %d", patch.ID)}
}
diff --git a/store/instance.go b/store/instance.go
index f7fb19f238..52feb4607f 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -134,9 +134,9 @@ func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("instance not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d instances with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d instances with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.InstanceCache, list[0].ID, list[0]); err != nil {
@@ -346,5 +346,5 @@ func patchInstance(ctx context.Context, tx *Tx, patch *api.InstancePatch) (*api.
return &instance, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("instance ID not found: %d", patch.ID)}
}
diff --git a/store/instance_user.go b/store/instance_user.go
index 6734f13aaf..2b9b91ff9a 100644
--- a/store/instance_user.go
+++ b/store/instance_user.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -179,7 +179,7 @@ func deleteInstanceUser(ctx context.Context, tx *Tx, delete *api.InstanceUserDel
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance user ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("instance user ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/issue.go b/store/issue.go
index 691f2b8ed3..e9b9af077f 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -6,8 +6,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -90,9 +90,9 @@ func (s *IssueService) FindIssue(ctx context.Context, find *api.IssueFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("issue not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("issue not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d issues with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d issues with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.IssueCache, list[0].ID, list[0]); err != nil {
@@ -331,5 +331,5 @@ func (s *IssueService) patchIssue(ctx context.Context, tx *Tx, patch *api.IssueP
return &issue, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("unable to find issue ID to update: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("unable to find issue ID to update: %d", patch.ID)}
}
diff --git a/store/issue_subscriber.go b/store/issue_subscriber.go
index 32a1777e25..f941b0f9f1 100644
--- a/store/issue_subscriber.go
+++ b/store/issue_subscriber.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -167,7 +167,7 @@ func deleteIssueSubscriber(ctx context.Context, tx *Tx, delete *api.IssueSubscri
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("subscriber %d not found in issue %d", delete.SubscriberId, delete.IssueId)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("subscriber %d not found in issue %d", delete.SubscriberId, delete.IssueId)}
}
return nil
diff --git a/store/member.go b/store/member.go
index bbd9c79798..d3bc6e323a 100644
--- a/store/member.go
+++ b/store/member.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -100,9 +100,9 @@ func (s *MemberService) FindMember(ctx context.Context, find *api.MemberFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("member not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("member not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d members with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d members with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.MemberCache, list[0].PrincipalId, list[0]); err != nil {
@@ -288,5 +288,5 @@ func patchMember(ctx context.Context, tx *Tx, patch *api.MemberPatch) (*api.Memb
return &member, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("member ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("member ID not found: %d", patch.ID)}
}
diff --git a/store/pipeline.go b/store/pipeline.go
index 84984a42a0..28919e73cf 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -100,9 +100,9 @@ func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("pipeline not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("pipeline not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d pipelines with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d pipelines with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.PipelineCache, list[0].ID, list[0]); err != nil {
@@ -269,5 +269,5 @@ func (s *PipelineService) patchPipeline(ctx context.Context, tx *Tx, patch *api.
return &pipeline, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("pipeline ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("pipeline ID not found: %d", patch.ID)}
}
diff --git a/store/principal.go b/store/principal.go
index 1f31eefef8..5f20576d40 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -100,9 +100,9 @@ func (s *PrincipalService) FindPrincipal(ctx context.Context, find *api.Principa
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("principal not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("principal not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d principals with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d principals with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.PrincipalCache, list[0].ID, list[0]); err != nil {
@@ -286,5 +286,5 @@ func patchPrincipal(ctx context.Context, tx *Tx, patch *api.PrincipalPatch) (*ap
return &principal, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("principal ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("principal ID not found: %d", patch.ID)}
}
diff --git a/store/project.go b/store/project.go
index c594f98d3d..53722dd9f2 100644
--- a/store/project.go
+++ b/store/project.go
@@ -6,8 +6,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -101,9 +101,9 @@ func (s *ProjectService) FindProject(ctx context.Context, find *api.ProjectFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d projects with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d projects with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.ProjectCache, list[0].ID, list[0]); err != nil {
@@ -315,5 +315,5 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
return &project, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project ID not found: %d", patch.ID)}
}
diff --git a/store/project_member.go b/store/project_member.go
index e1151bac77..f31e9d4933 100644
--- a/store/project_member.go
+++ b/store/project_member.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -244,7 +244,7 @@ func patchProjectMember(ctx context.Context, tx *Tx, patch *api.ProjectMemberPat
return &projectMember, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project member ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project member ID not found: %d", patch.ID)}
}
// deleteProjectMember permanently deletes a projectMember by ID.
@@ -257,7 +257,7 @@ func deleteProjectMember(ctx context.Context, tx *Tx, delete *api.ProjectMemberD
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project member ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project member ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/project_webhook.go b/store/project_webhook.go
index 073e68cb6a..c0c908ca1c 100644
--- a/store/project_webhook.go
+++ b/store/project_webhook.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *ProjectWebhookService) FindProjectWebhook(ctx context.Context, find *ap
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project hook not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project hook not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d project hooks with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d project hooks with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -298,7 +298,7 @@ func patchProjectWebhook(ctx context.Context, tx *Tx, patch *api.ProjectWebhookP
return &projectWebhook, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project hook ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project hook ID not found: %d", patch.ID)}
}
// deleteProjectWebhook permanently deletes a projectWebhook by ID.
@@ -311,7 +311,7 @@ func deleteProjectWebhook(ctx context.Context, tx *Tx, delete *api.ProjectWebhoo
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project hook ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("project hook ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/repository.go b/store/repository.go
index a9be18d2d1..b5a8e016c8 100644
--- a/store/repository.go
+++ b/store/repository.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -77,9 +77,9 @@ func (s *RepositoryService) FindRepository(ctx context.Context, find *api.Reposi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("repository not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d repositories with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d repositories with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -359,7 +359,7 @@ func patchRepository(ctx context.Context, tx *Tx, patch *api.RepositoryPatch) (*
return &repository, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("repository ID not found: %d", patch.ID)}
}
// deleteRepository permanently deletes a repository by ID.
@@ -383,7 +383,7 @@ func (s *RepositoryService) deleteRepository(ctx context.Context, tx *Tx, delete
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository not found for project ID: %d", delete.ProjectId)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("repository not found for project ID: %d", delete.ProjectId)}
}
return nil
diff --git a/store/setting.go b/store/setting.go
index ed76b3dff1..82a1e77508 100644
--- a/store/setting.go
+++ b/store/setting.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -34,7 +34,7 @@ func (s *SettingService) CreateSettingIfNotExist(ctx context.Context, create *ap
}
setting, err := s.FindSetting(ctx, find)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, FormatError(err)
@@ -87,9 +87,9 @@ func (s *SettingService) FindSetting(ctx context.Context, find *api.SettingFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("setting not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("setting not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
@@ -243,5 +243,5 @@ func patchSetting(ctx context.Context, tx *Tx, patch *api.SettingPatch) (*api.Se
return &setting, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("setting not found: %s", patch.Name)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("setting not found: %s", patch.Name)}
}
diff --git a/store/sqlite.go b/store/sqlite.go
index 3b41942f7a..e9a07153f2 100644
--- a/store/sqlite.go
+++ b/store/sqlite.go
@@ -12,7 +12,7 @@ import (
"strings"
"time"
- "github.com/bytebase/bytebase"
+ "github.com/bytebase/bytebase/common"
_ "github.com/mattn/go-sqlite3"
"go.uber.org/zap"
)
@@ -330,29 +330,29 @@ func FormatError(err error) error {
switch err.Error() {
case "UNIQUE constraint failed: principal.email":
- return bytebase.Errorf(bytebase.ECONFLICT, "email already exists")
+ return common.Errorf(common.ECONFLICT, "email already exists")
case "UNIQUE constraint failed: member.principal_id":
- return bytebase.Errorf(bytebase.ECONFLICT, "member already exists")
+ return common.Errorf(common.ECONFLICT, "member already exists")
case "UNIQUE constraint failed: environment.name":
- return bytebase.Errorf(bytebase.ECONFLICT, "environment name already exists")
+ return common.Errorf(common.ECONFLICT, "environment name already exists")
case "UNIQUE constraint failed: project.key":
- return bytebase.Errorf(bytebase.ECONFLICT, "project key already exists")
+ return common.Errorf(common.ECONFLICT, "project key already exists")
case "UNIQUE constraint failed: project_webhook.project_id, project_webhook.url":
- return bytebase.Errorf(bytebase.ECONFLICT, "webhook url already exists")
+ return common.Errorf(common.ECONFLICT, "webhook url already exists")
case "UNIQUE constraint failed: project_member.project_id, project_member.principal_id":
- return bytebase.Errorf(bytebase.ECONFLICT, "project member already exists")
+ return common.Errorf(common.ECONFLICT, "project member already exists")
case "UNIQUE constraint failed: db.instance_id, db.name":
- return bytebase.Errorf(bytebase.ECONFLICT, "database name already exists")
+ return common.Errorf(common.ECONFLICT, "database name already exists")
case "UNIQUE constraint failed: data_source.instance_id, data_source.name":
- return bytebase.Errorf(bytebase.ECONFLICT, "data source name already exists")
+ return common.Errorf(common.ECONFLICT, "data source name already exists")
case "UNIQUE constraint failed: backup.database_id, backup.name":
- return bytebase.Errorf(bytebase.ECONFLICT, "backup name already exists")
+ return common.Errorf(common.ECONFLICT, "backup name already exists")
case "UNIQUE constraint failed: bookmark.creator_id, bookmark.link":
- return bytebase.Errorf(bytebase.ECONFLICT, "bookmark already exists")
+ return common.Errorf(common.ECONFLICT, "bookmark already exists")
case "UNIQUE constraint failed: repo.project_id":
- return bytebase.Errorf(bytebase.ECONFLICT, "project has already linked repository")
+ return common.Errorf(common.ECONFLICT, "project has already linked repository")
case "UNIQUE constraint failed: issue_subscriber.issue_id, issue_subscriber.subscriber_id":
- return bytebase.Errorf(bytebase.ECONFLICT, "issue subscriber already exists")
+ return common.Errorf(common.ECONFLICT, "issue subscriber already exists")
default:
return err
}
diff --git a/store/stage.go b/store/stage.go
index f4ab351f52..08205e8c02 100644
--- a/store/stage.go
+++ b/store/stage.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("stage not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("stage not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d stages with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d stages with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/table.go b/store/table.go
index 710944042b..c06498a299 100644
--- a/store/table.go
+++ b/store/table.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *TableService) FindTable(ctx context.Context, find *api.TableFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("table not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("table not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d tables with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d tables with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -307,5 +307,5 @@ func (s *TableService) patchTable(ctx context.Context, tx *Tx, patch *api.TableP
return &table, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("table ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("table ID not found: %d", patch.ID)}
}
diff --git a/store/table_index.go b/store/table_index.go
index d9c1d4f3ce..e9e7d18baa 100644
--- a/store/table_index.go
+++ b/store/table_index.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("index not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("index not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d indexs with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d indexs with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -303,5 +303,5 @@ func (s *IndexService) patchIndex(ctx context.Context, tx *Tx, patch *api.IndexP
return &index, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("index ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("index ID not found: %d", patch.ID)}
}
diff --git a/store/task.go b/store/task.go
index 85991043ad..a24e95e212 100644
--- a/store/task.go
+++ b/store/task.go
@@ -7,8 +7,8 @@ import (
"strings"
"time"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -200,9 +200,9 @@ func (s *TaskService) findTask(ctx context.Context, tx *Tx, find *api.TaskFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("task not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d tasks with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d tasks with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -307,7 +307,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
}
taskRun, err := s.TaskRunService.FindTaskRun(ctx, tx.Tx, taskRunFind)
if err != nil {
- if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
+ if common.ErrorCode(err) == common.ENOTFOUND {
if patch.Status != api.TaskRunning {
return nil, fmt.Errorf("no applicable running task to change status")
}
@@ -402,5 +402,5 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
return &task, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("task ID not found: %d", patch.ID)}
}
diff --git a/store/task_run.go b/store/task_run.go
index fb8560d6f5..9902ef0192 100644
--- a/store/task_run.go
+++ b/store/task_run.go
@@ -6,8 +6,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -93,9 +93,9 @@ func (s *TaskRunService) FindTaskRun(ctx context.Context, tx *sql.Tx, find *api.
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task run not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("task run not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d task runs with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d task runs with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/vcs.go b/store/vcs.go
index 6d305726ac..9b4a392cda 100644
--- a/store/vcs.go
+++ b/store/vcs.go
@@ -5,8 +5,8 @@ import (
"fmt"
"strings"
- "github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -75,9 +75,9 @@ func (s *VCSService) FindVCS(ctx context.Context, find *api.VCSFind) (*api.VCS,
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("vcs not found: %+v", find)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("vcs not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d vcss with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.ECONFLICT, Message: fmt.Sprintf("found %d vcss with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -285,7 +285,7 @@ func patchVCS(ctx context.Context, tx *Tx, patch *api.VCSPatch) (*api.VCS, error
return &vcs, nil
}
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("vcs ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("vcs ID not found: %d", patch.ID)}
}
// deleteVCS permanently deletes a vcs by ID.
@@ -298,7 +298,7 @@ func deleteVCS(ctx context.Context, tx *Tx, delete *api.VCSDelete) error {
rows, _ := result.RowsAffected()
if rows == 0 {
- return &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("vcs ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.ENOTFOUND, Message: fmt.Sprintf("vcs ID not found: %d", delete.ID)}
}
return nil