diff --git a/accounting/consumer/metering.go b/accounting/consumer/metering.go index 10fd77af..e2afb3a5 100644 --- a/accounting/consumer/metering.go +++ b/accounting/consumer/metering.go @@ -41,7 +41,7 @@ func (m *Metering) startMetering() { } func (m *Metering) preReadMsgs() { - var err error = nil + var err error var i int = 0 for { i++ diff --git a/api/handler/repo.go b/api/handler/repo.go index 8ebc865c..04b77443 100644 --- a/api/handler/repo.go +++ b/api/handler/repo.go @@ -1599,10 +1599,8 @@ func getSourceRepoPathFromSourceUrl(sourceUrl string) (string, error) { // Remove leading and trailing slashes path := strings.Trim(parsedURL.Path, "/") - // Remove ".git" suffix if present - if strings.HasSuffix(path, ".git") { - path = strings.TrimSuffix(path, ".git") - } + // Remove ".git" suffix + path = strings.TrimSuffix(path, ".git") return path, nil } diff --git a/api/handler/runtime_architecture.go b/api/handler/runtime_architecture.go index 6c73a798..43062a3e 100644 --- a/api/handler/runtime_architecture.go +++ b/api/handler/runtime_architecture.go @@ -174,7 +174,12 @@ func (r *RuntimeArchitectureHandler) ScanArchitecture(ctx *gin.Context) { } var req types.RuntimeFrameworkModels - ctx.ShouldBindJSON(&req) + err = ctx.ShouldBindJSON(&req) + if err != nil { + slog.Error("Failed to bind json", slog.Any("error", err)) + httpbase.BadRequest(ctx, err.Error()) + return + } err = r.rac.ScanArchitecture(ctx, id, scanType, req.Models) if err != nil { diff --git a/api/middleware/authenticator.go b/api/middleware/authenticator.go index dadac4fa..6cec0c45 100644 --- a/api/middleware/authenticator.go +++ b/api/middleware/authenticator.go @@ -35,7 +35,12 @@ func BuildJwtSession(jwtSignKey string) gin.HandlerFunc { } sessions.Default(c).Set(httpbase.CurrentUserCtxVar, claims.CurrentUser) - sessions.Default(c).Save() + err = sessions.Default(c).Save() + if err != nil { + slog.Error("fail to save session", slog.Any("error", err)) + c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": err.Error()}) + return + } c.Next() } diff --git a/api/router/api.go b/api/router/api.go index 9c4621a9..f234ed1b 100644 --- a/api/router/api.go +++ b/api/router/api.go @@ -418,7 +418,7 @@ func createModelRoutes(config *config.Config, apiGroup *gin.RouterGroup, needAPI // The DownloadFile has a different file_path format for lfs files and non-lfs files, // and an lfs parameter needs to be added. // 2. DownloadFile returns an object store url for lfs files, while SDKDownload redirects directly. - modelsGroup.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.ModelRepo), repoCommonHandler.DownloadFile) + modelsGroup.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.ModelRepo), repoCommonHandler.ResolveDownload) modelsGroup.GET("/:namespace/:name/resolve/*file_path", middleware.RepoType(types.ModelRepo), repoCommonHandler.ResolveDownload) modelsGroup.POST("/:namespace/:name/raw/*file_path", middleware.RepoType(types.ModelRepo), repoCommonHandler.CreateFile) modelsGroup.PUT("/:namespace/:name/raw/*file_path", middleware.RepoType(types.ModelRepo), repoCommonHandler.UpdateFile) @@ -502,7 +502,7 @@ func createDatasetRoutes(config *config.Config, apiGroup *gin.RouterGroup, dsHan datasetsGroup.POST("/:namespace/:name/raw/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.CreateFile) datasetsGroup.GET("/:namespace/:name/raw/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.FileRaw) datasetsGroup.GET("/:namespace/:name/blob/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.FileInfo) - datasetsGroup.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.DownloadFile) + datasetsGroup.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.ResolveDownload) datasetsGroup.GET("/:namespace/:name/resolve/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.ResolveDownload) datasetsGroup.PUT("/:namespace/:name/raw/*file_path", middleware.RepoType(types.DatasetRepo), repoCommonHandler.UpdateFile) datasetsGroup.POST("/:namespace/:name/update_downloads", middleware.RepoType(types.DatasetRepo), repoCommonHandler.UpdateDownloads) @@ -541,7 +541,7 @@ func createCodeRoutes(config *config.Config, apiGroup *gin.RouterGroup, codeHand codesGroup.POST("/:namespace/:name/raw/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.CreateFile) codesGroup.GET("/:namespace/:name/raw/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.FileRaw) codesGroup.GET("/:namespace/:name/blob/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.FileInfo) - codesGroup.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.DownloadFile) + codesGroup.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.ResolveDownload) codesGroup.GET("/:namespace/:name/resolve/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.ResolveDownload) codesGroup.PUT("/:namespace/:name/raw/*file_path", middleware.RepoType(types.CodeRepo), repoCommonHandler.UpdateFile) codesGroup.POST("/:namespace/:name/update_downloads", middleware.RepoType(types.CodeRepo), repoCommonHandler.UpdateDownloads) @@ -594,7 +594,7 @@ func createSpaceRoutes(config *config.Config, apiGroup *gin.RouterGroup, spaceHa spaces.POST("/:namespace/:name/raw/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.CreateFile) spaces.GET("/:namespace/:name/raw/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.FileRaw) spaces.GET("/:namespace/:name/blob/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.FileInfo) - spaces.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.DownloadFile) + spaces.GET("/:namespace/:name/download/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.ResolveDownload) spaces.GET("/:namespace/:name/resolve/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.ResolveDownload) spaces.PUT("/:namespace/:name/raw/*file_path", middleware.RepoType(types.SpaceRepo), repoCommonHandler.UpdateFile) spaces.POST("/:namespace/:name/update_downloads", middleware.RepoType(types.SpaceRepo), repoCommonHandler.UpdateDownloads) diff --git a/builder/deploy/common/appname.go b/builder/deploy/common/appname.go index fa7aedbb..3f2458bb 100644 --- a/builder/deploy/common/appname.go +++ b/builder/deploy/common/appname.go @@ -57,9 +57,8 @@ func stringToNumber(encoded string) (int64, error) { var num int64 base := int64(len(alphabet)) - encodedRunes := []rune(encoded) - for _, r := range encodedRunes { + for _, r := range encoded { num = num*base + alphabetMap[r] } diff --git a/builder/deploy/deployer.go b/builder/deploy/deployer.go index 2365db6a..e3937807 100644 --- a/builder/deploy/deployer.go +++ b/builder/deploy/deployer.go @@ -79,7 +79,12 @@ func newDeployer(s scheduler.Scheduler, ib imagebuilder.Builder, ir imagerunner. } go d.refreshStatus() - go d.s.Run() + go func() { + err = d.s.Run() + if err != nil { + slog.Error("run scheduler failed", slog.Any("error", err)) + } + }() go d.startAccounting() return d, nil @@ -105,8 +110,8 @@ func (d *deployer) GenerateUniqueSvcName(dr types.DeployRepo) string { func (d *deployer) serverlessDeploy(ctx context.Context, dr types.DeployRepo) (*database.Deploy, error) { var ( - deploy *database.Deploy = nil - err error = nil + deploy *database.Deploy + err error ) slog.Info("do deployer.serverlessDeploy check type", slog.Any("dr.Type", dr.Type)) if dr.Type == types.SpaceType { @@ -217,14 +222,24 @@ func (d *deployer) Deploy(ctx context.Context, dr types.DeployRepo) (int64, erro Status: bldTaskStatus, Message: bldTaskMsg, } - d.store.CreateDeployTask(ctx, buildTask) + err = d.store.CreateDeployTask(ctx, buildTask) + if err != nil { + return -1, fmt.Errorf("failed to create deploy task: %w", err) + } runTask := &database.DeployTask{ DeployID: deploy.ID, TaskType: 1, } - d.store.CreateDeployTask(ctx, runTask) + err = d.store.CreateDeployTask(ctx, runTask) + if err != nil { + return -1, fmt.Errorf("failed to create deploy task: %w", err) + } - go d.s.Queue(buildTask.ID) + go func() { + if err := d.s.Queue(buildTask.ID); err != nil { + slog.Error("failed to queue task", slog.Any("error", err)) + } + }() return deploy.ID, nil } @@ -509,10 +524,10 @@ func (d *deployer) UpdateCluster(ctx context.Context, data types.ClusterRequest) // UpdateDeploy implements Deployer. func (d *deployer) UpdateDeploy(ctx context.Context, dur *types.DeployUpdateReq, deploy *database.Deploy) error { var ( - frame *database.RuntimeFramework = nil - resource *database.SpaceResource = nil - hardware *types.HardWare = nil - err error = nil + frame *database.RuntimeFramework + resource *database.SpaceResource + hardware *types.HardWare + err error ) if dur.RuntimeFrameworkID != nil { @@ -602,9 +617,12 @@ func (d *deployer) StartDeploy(ctx context.Context, deploy *database.Deploy) err DeployID: deploy.ID, TaskType: 1, } - d.store.CreateDeployTask(ctx, runTask) + err = d.store.CreateDeployTask(ctx, runTask) + if err != nil { + return fmt.Errorf("failed to create deploy task: %w", err) + } - go d.s.Queue(runTask.ID) + go func() { _ = d.s.Queue(runTask.ID) }() return nil } diff --git a/builder/deploy/scheduler/scheduler.go b/builder/deploy/scheduler/scheduler.go index bb4a734a..47253bfe 100644 --- a/builder/deploy/scheduler/scheduler.go +++ b/builder/deploy/scheduler/scheduler.go @@ -88,7 +88,7 @@ func (rs *FIFOScheduler) Run() error { rs.failDeployFollowingTasks(t.WatchID(), err.Error()) } - rs.next() + _, _ = rs.next() }(t) } @@ -97,9 +97,9 @@ func (rs *FIFOScheduler) Run() error { func (rs *FIFOScheduler) Queue(deployTaskID int64) error { // simply trigger next task - rs.next() + _, err := rs.next() - return nil + return err } // run next task @@ -179,7 +179,10 @@ func (rs *FIFOScheduler) next() (Runner, error) { // mark task as cancelled deployTask.Status = cancelled deployTask.Message = "repo not found" - rs.store.UpdateDeployTask(ctx, deployTask) + err = rs.store.UpdateDeployTask(ctx, deployTask) + if err != nil { + slog.Error("update deploy task failed", "error", err) + } } t = &sleepTask{ du: 5 * time.Second, diff --git a/builder/git/gitserver/gitaly/file.go b/builder/git/gitserver/gitaly/file.go index 51eebe1e..8a389ad7 100644 --- a/builder/git/gitserver/gitaly/file.go +++ b/builder/git/gitserver/gitaly/file.go @@ -204,9 +204,18 @@ func (c *Client) CreateRepoFile(req *types.CreateFileReq) (err error) { }, }, } - userCommitFilesClient.Send(actions[0]) - userCommitFilesClient.Send(actions[1]) - userCommitFilesClient.Send(actions[2]) + err = userCommitFilesClient.Send(actions[0]) + if err != nil { + return err + } + err = userCommitFilesClient.Send(actions[1]) + if err != nil { + return err + } + err = userCommitFilesClient.Send(actions[2]) + if err != nil { + return err + } _, err = userCommitFilesClient.CloseAndRecv() if err != nil { return err @@ -281,9 +290,18 @@ func (c *Client) UpdateRepoFile(req *types.UpdateFileReq) (err error) { }, }, } - userCommitFilesClient.Send(actions[0]) - userCommitFilesClient.Send(actions[1]) - userCommitFilesClient.Send(actions[2]) + err = userCommitFilesClient.Send(actions[0]) + if err != nil { + return err + } + err = userCommitFilesClient.Send(actions[1]) + if err != nil { + return err + } + err = userCommitFilesClient.Send(actions[2]) + if err != nil { + return err + } _, err = userCommitFilesClient.CloseAndRecv() if err != nil { return err @@ -349,8 +367,14 @@ func (c *Client) DeleteRepoFile(req *types.DeleteFileReq) (err error) { }, }, } - userCommitFilesClient.Send(actions[0]) - userCommitFilesClient.Send(actions[1]) + err = userCommitFilesClient.Send(actions[0]) + if err != nil { + return err + } + err = userCommitFilesClient.Send(actions[1]) + if err != nil { + return err + } _, err = userCommitFilesClient.CloseAndRecv() if err != nil { return err diff --git a/builder/git/gitserver/gitaly/info_refs.go b/builder/git/gitserver/gitaly/info_refs.go index fe90394c..b80471e9 100644 --- a/builder/git/gitserver/gitaly/info_refs.go +++ b/builder/git/gitserver/gitaly/info_refs.go @@ -4,8 +4,8 @@ import ( "context" "fmt" "io" + "log/slog" "strconv" - "time" gitalyclient "gitlab.com/gitlab-org/gitaly/v16/client" gitalypb "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" @@ -13,9 +13,9 @@ import ( "opencsg.com/csghub-server/builder/git/gitserver" ) -var ( - uploadPackTimeout = 10 * time.Minute -) +// var ( +// uploadPackTimeout = 10 * time.Minute +// ) func (c *Client) InfoRefsResponse(ctx context.Context, req gitserver.InfoRefsReq) (io.Reader, error) { repoType := fmt.Sprintf("%ss", string(req.RepoType)) @@ -131,7 +131,10 @@ func (c *Client) ReceivePack(ctx context.Context, req gitserver.ReceivePackReq) return stream.Send(&gitalypb.PostReceivePackRequest{Data: data}) }) _, err := io.Copy(sw, req.Request.Body) - stream.CloseSend() + errClose := stream.CloseSend() + if errClose != nil { + slog.Error("closeSend stream failed", slog.Any("error", errClose)) + } errC <- err }() diff --git a/builder/git/gitserver/gitea/client.go b/builder/git/gitserver/gitea/client.go index af348d68..b5bbc8ad 100644 --- a/builder/git/gitserver/gitea/client.go +++ b/builder/git/gitserver/gitea/client.go @@ -109,13 +109,13 @@ func generateAccessTokenFromGitea(config *config.Config) (string, error) { } jsonData, err := json.Marshal(data) if err != nil { - slog.Error("Error encoding JSON data:", err) + slog.Error("Error encoding JSON data:", "error", err) return "", err } req, err := http.NewRequest("POST", giteaUrl, bytes.NewBuffer(jsonData)) if err != nil { - slog.Error("Error creating request:", err) + slog.Error("Error creating request:", "error", err) return "", err } @@ -126,21 +126,21 @@ func generateAccessTokenFromGitea(config *config.Config) (string, error) { client := http.Client{} resp, err := client.Do(req) if err != nil { - slog.Error("Error sending request:", err) + slog.Error("Error sending request:", "error", err) return "", err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - slog.Error("Error reading response body:", err) + slog.Error("Error reading response body:", "error", err) return "", err } var tokenResponse TokenResponse err = json.Unmarshal(body, &tokenResponse) if err != nil { - slog.Error("Error decoding JSON response:", err) + slog.Error("Error decoding JSON response:", "error", err) return "", err } diff --git a/builder/git/membership/gitea/client.go b/builder/git/membership/gitea/client.go index eb5ab289..c2f0258c 100644 --- a/builder/git/membership/gitea/client.go +++ b/builder/git/membership/gitea/client.go @@ -109,13 +109,13 @@ func generateAccessTokenFromGitea(config *config.Config) (string, error) { } jsonData, err := json.Marshal(data) if err != nil { - slog.Error("Error encoding JSON data:", err) + slog.Error("Error encoding JSON data:", "error", err) return "", err } req, err := http.NewRequest("POST", giteaUrl, bytes.NewBuffer(jsonData)) if err != nil { - slog.Error("Error creating request:", err) + slog.Error("Error creating request:", "error", err) return "", err } @@ -126,21 +126,21 @@ func generateAccessTokenFromGitea(config *config.Config) (string, error) { client := http.Client{} resp, err := client.Do(req) if err != nil { - slog.Error("Error sending request:", err) + slog.Error("Error sending request:", "error", err) return "", err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - slog.Error("Error reading response body:", err) + slog.Error("Error reading response body:", "error", err) return "", err } var tokenResponse TokenResponse err = json.Unmarshal(body, &tokenResponse) if err != nil { - slog.Error("Error decoding JSON response:", err) + slog.Error("Error decoding JSON response:", "error", err) return "", err } diff --git a/builder/git/mirrorserver/gitea/mirror_client.go b/builder/git/mirrorserver/gitea/mirror_client.go index ef760e8b..e6e2e326 100644 --- a/builder/git/mirrorserver/gitea/mirror_client.go +++ b/builder/git/mirrorserver/gitea/mirror_client.go @@ -97,13 +97,13 @@ func generateAccessTokenFromGitea(config *config.Config) (string, error) { } jsonData, err := json.Marshal(data) if err != nil { - slog.Error("Error encoding JSON data:", err) + slog.Error("Error encoding JSON data:", "error", err) return "", err } req, err := http.NewRequest("POST", giteaUrl, bytes.NewBuffer(jsonData)) if err != nil { - slog.Error("Error creating request:", err) + slog.Error("Error creating request:", "error", err) return "", err } @@ -114,21 +114,21 @@ func generateAccessTokenFromGitea(config *config.Config) (string, error) { client := http.Client{} resp, err := client.Do(req) if err != nil { - slog.Error("Error sending request:", err) + slog.Error("Error sending request:", "error", err) return "", err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - slog.Error("Error reading response body:", err) + slog.Error("Error reading response body:", "error", err) return "", err } var tokenResponse TokenResponse err = json.Unmarshal(body, &tokenResponse) if err != nil { - slog.Error("Error decoding JSON response:", err) + slog.Error("Error decoding JSON response:", "error", err) return "", err } diff --git a/builder/git/mirrorserver/types.go b/builder/git/mirrorserver/types.go index 8fcc8664..b2f28fe3 100644 --- a/builder/git/mirrorserver/types.go +++ b/builder/git/mirrorserver/types.go @@ -51,7 +51,7 @@ type TaskStatus int type GetRepoInfoReq struct { Namespace string `json:"namespace"` - Name string `json:name"` + Name string `json:"name"` } type RepoInfo struct { diff --git a/builder/inference/llm_infer.go b/builder/inference/llm_infer.go index 71029e93..3047b5a1 100644 --- a/builder/inference/llm_infer.go +++ b/builder/inference/llm_infer.go @@ -168,7 +168,10 @@ func (c *llmInferClient) GetModelInfo(id ModelID) (ModelInfo, error) { func (c *llmInferClient) CallPredict(url string, req *PredictRequest) (*PredictResponse, error) { var body bytes.Buffer - json.NewEncoder(&body).Encode(req) + err := json.NewEncoder(&body).Encode(req) + if err != nil { + return nil, err + } resp, err := c.hc.Post(url, "application/json", &body) if err != nil { return nil, fmt.Errorf("failed to send http request,error: %w", err) diff --git a/builder/multisync/client.go b/builder/multisync/client.go index 4a8b7884..8bec9cc4 100644 --- a/builder/multisync/client.go +++ b/builder/multisync/client.go @@ -45,7 +45,7 @@ func (c *commonClient) Latest(ctx context.Context, currentVersion int64) (types. if resp.StatusCode != http.StatusOK { var data bytes.Buffer - data.ReadFrom(resp.Body) + _, _ = data.ReadFrom(resp.Body) return types.SyncVersionResponse{}, fmt.Errorf("failed to get latest version from endpoint %s, param cur:%d, status code: %d, body: %s", c.endpoint, currentVersion, resp.StatusCode, data.String()) } diff --git a/builder/proxy/reverse_proxy.go b/builder/proxy/reverse_proxy.go index 2f6689bb..17f95432 100644 --- a/builder/proxy/reverse_proxy.go +++ b/builder/proxy/reverse_proxy.go @@ -8,7 +8,6 @@ import ( type ReverseProxy struct { target *url.URL - proxy *httputil.ReverseProxy } func NewReverseProxy(target string) (*ReverseProxy, error) { diff --git a/builder/store/database/deploy_task.go b/builder/store/database/deploy_task.go index d455a26a..915e80d7 100644 --- a/builder/store/database/deploy_task.go +++ b/builder/store/database/deploy_task.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "fmt" + "log/slog" "time" "github.com/uptrace/bun" @@ -171,7 +172,9 @@ func (s *deployTaskStoreImpl) UpdateInTx(ctx context.Context, deployColumns, dep Column(deployColumns...). WherePK().Exec(ctx) if err != nil { - tx.Rollback() + if ree := tx.Rollback(); ree != nil { + slog.Error("rollback failed", "error", err) + } return fmt.Errorf("failed to update deploy,%w", err) } } @@ -187,7 +190,9 @@ func (s *deployTaskStoreImpl) UpdateInTx(ctx context.Context, deployColumns, dep Bulk(). Exec(ctx) if err != nil { - tx.Rollback() + if ree := tx.Rollback(); ree != nil { + slog.Error("rollback failed", "error", err) + } return fmt.Errorf("failed to update deploy tasks in tx,%w", err) } diff --git a/builder/store/database/migrations/20240313091943_create_space_deploy.go b/builder/store/database/migrations/20240313091943_create_space_deploy.go index d377ab84..9483abc5 100644 --- a/builder/store/database/migrations/20240313091943_create_space_deploy.go +++ b/builder/store/database/migrations/20240313091943_create_space_deploy.go @@ -26,7 +26,7 @@ type Deploy struct { func init() { Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error { - dropTables(ctx, db, database.Space{}) + _ = dropTables(ctx, db, database.Space{}) return createTables(ctx, db, database.Space{}, Deploy{}, database.DeployTask{}) }, func(ctx context.Context, db *bun.DB) error { return dropTables(ctx, db, Deploy{}, database.DeployTask{}) diff --git a/builder/store/database/migrations/20240507023247_create_repo_recommendation_tables.go b/builder/store/database/migrations/20240507023247_create_repo_recommendation_tables.go index d91f0298..bdfa9009 100644 --- a/builder/store/database/migrations/20240507023247_create_repo_recommendation_tables.go +++ b/builder/store/database/migrations/20240507023247_create_repo_recommendation_tables.go @@ -11,7 +11,7 @@ import ( func init() { Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error { - dropTables(ctx, db, database.RecomOpWeight{}, database.RecomRepoScore{}, database.RecomWeight{}) + _ = dropTables(ctx, db, database.RecomOpWeight{}, database.RecomRepoScore{}, database.RecomWeight{}) err := createTables(ctx, db, database.RecomOpWeight{}, database.RecomRepoScore{}, database.RecomWeight{}) if err != nil { return err diff --git a/builder/store/database/repo_relation.go b/builder/store/database/repo_relation.go index 595c5d9d..ad2e7398 100644 --- a/builder/store/database/repo_relation.go +++ b/builder/store/database/repo_relation.go @@ -3,6 +3,7 @@ package database import ( "context" "fmt" + "log/slog" ) type repoRelationsStoreImpl struct { @@ -66,7 +67,9 @@ func (r *repoRelationsStoreImpl) Override(ctx context.Context, from int64, to .. } _, err = tx.NewDelete().Model((*RepoRelation)(nil)).Where("from_repo_id = ?", from).Exec(ctx) if err != nil { - tx.Rollback() + if er := tx.Rollback(); er != nil { + slog.Error("rollback failed", "error", er) + } return fmt.Errorf("failed to delete existing relations: %w", err) } @@ -74,7 +77,9 @@ func (r *repoRelationsStoreImpl) Override(ctx context.Context, from int64, to .. _, err = tx.NewInsert().Model(&relations). Exec(ctx) if err != nil { - tx.Rollback() + if er := tx.Rollback(); er != nil { + slog.Error("tx rollback failed", "error", er) + } return fmt.Errorf("failed to insert relations: %w", err) } } diff --git a/builder/store/database/tag.go b/builder/store/database/tag.go index 1c6ed6e2..424f644c 100644 --- a/builder/store/database/tag.go +++ b/builder/store/database/tag.go @@ -254,10 +254,13 @@ func (ts *tagStoreImpl) SetMetaTags(ctx context.Context, repoType types.Reposito // select all repo tags which are not Library tags err = ts.db.Operator.Core.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { // remove all tags of the repository not belongs to category "Library", and then add new tags - tx.NewDelete(). + _, err := tx.NewDelete(). Model(&RepositoryTag{}). Where("repository_id =? and tag_id in (?)", repo.ID, bun.In(metaTagIds)). Exec(ctx) + if err != nil { + return err + } // no new tags to insert if len(tags) == 0 { return nil @@ -270,7 +273,7 @@ func (ts *tagStoreImpl) SetMetaTags(ctx context.Context, repoType types.Reposito repoTags = append(repoTags, repoTag) } // batch insert - _, err := tx.NewInsert().Model(&repoTags).Exec(ctx) + _, err = tx.NewInsert().Model(&repoTags).Exec(ctx) if err != nil { return fmt.Errorf("failed to batch insert repository meta tags, path:%v/%v,error:%w", namespace, name, err) } diff --git a/cmd/csghub-server/cmd/cron/create_push_mirror.go b/cmd/csghub-server/cmd/cron/create_push_mirror.go index 84e83785..f9b9af0f 100644 --- a/cmd/csghub-server/cmd/cron/create_push_mirror.go +++ b/cmd/csghub-server/cmd/cron/create_push_mirror.go @@ -54,6 +54,10 @@ var cmdCreatePushMirror = &cobra.Command{ slog.Error("failed to create mirror component", "err", err) return } - c.CreatePushMirrorForFinishedMirrorTask(cmd.Context()) + err = c.CreatePushMirrorForFinishedMirrorTask(cmd.Context()) + if err != nil { + slog.Error("failed to create push mirror task", "err", err) + return + } }, } diff --git a/cmd/csghub-server/cmd/cron/gen_telemetry.go b/cmd/csghub-server/cmd/cron/gen_telemetry.go index 5e8ad2dd..52ba9b45 100644 --- a/cmd/csghub-server/cmd/cron/gen_telemetry.go +++ b/cmd/csghub-server/cmd/cron/gen_telemetry.go @@ -110,7 +110,10 @@ func genTelemetry(config *config.Config) func(ctx context.Context) error { } if resp.StatusCode != http.StatusOK { var respData bytes.Buffer - io.Copy(&respData, resp.Body) + _, err = io.Copy(&respData, resp.Body) + if err != nil { + return fmt.Errorf("io copy failed %w", err) + } return fmt.Errorf("telemetry api returns error,url:%s, status:%d, body:%s", teleUrl, resp.StatusCode, respData.String()) } return nil diff --git a/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go b/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go index 9553e3df..f5b7b5ff 100644 --- a/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go +++ b/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log/slog" - "os" "path" "strings" "time" @@ -131,19 +130,19 @@ func checkAndUpdateLfsMetaObjects(config *config.Config, s3Client *s3.Client, lf objectKey := path.Join("lfs", pointer.RelativePath()) _, err := s3Client.StatObject(ctx, config.S3.Bucket, objectKey, minio.StatObjectOptions{}) if err != nil { - if os.IsNotExist(err) { - exists = false - } slog.Error("failed to check if lfs file exists", slog.String("oid", objectKey), slog.Any("error", err)) exists = false } else { exists = true } slog.Info("lfs file exists", slog.Bool("exists", exists)) - lfsMetaObjectStore.UpdateOrCreate(ctx, database.LfsMetaObject{ + _, err = lfsMetaObjectStore.UpdateOrCreate(ctx, database.LfsMetaObject{ Oid: pointer.Oid, Size: pointer.Size, RepositoryID: repo.ID, Existing: exists, }) + if err != nil { + slog.Error("lfsMetaObjectStore UpdateOrCreate failed", "error", err) + } } diff --git a/cmd/csghub-server/cmd/logscan/logscan.go b/cmd/csghub-server/cmd/logscan/logscan.go index 5d5b3927..eaabe445 100644 --- a/cmd/csghub-server/cmd/logscan/logscan.go +++ b/cmd/csghub-server/cmd/logscan/logscan.go @@ -92,11 +92,7 @@ var initCmd = &cobra.Command{ projectCount[date][repoType] = make(map[string]int64) } - if _, ok := projectCount[date][repoType][repoPath]; ok { - projectCount[date][repoType][repoPath]++ - } else { - projectCount[date][repoType][repoPath] = 1 - } + projectCount[date][repoType][repoPath]++ } sshMatches := sshPattern.FindStringSubmatch(line) if len(sshMatches) == 4 { @@ -111,11 +107,7 @@ var initCmd = &cobra.Command{ projectCount[date][repoType] = make(map[string]int64) } - if _, ok := projectCount[date][repoType][repoPath]; ok { - projectCount[date][repoType][repoPath]++ - } else { - projectCount[date][repoType][repoPath] = 1 - } + projectCount[date][repoType][repoPath]++ } } diff --git a/cmd/csghub-server/cmd/start/server.go b/cmd/csghub-server/cmd/start/server.go index 7a398093..a684674c 100644 --- a/cmd/csghub-server/cmd/start/server.go +++ b/cmd/csghub-server/cmd/start/server.go @@ -68,7 +68,7 @@ var serverCmd = &cobra.Command{ return fmt.Errorf("fail to initialize message queue, %w", err) } s3Internal := len(cfg.S3.InternalEndpoint) > 0 - deploy.Init(common.DeployConfig{ + err = deploy.Init(common.DeployConfig{ ImageBuilderURL: cfg.Space.BuilderEndpoint, ImageRunnerURL: cfg.Space.RunnerEndpoint, MonitorInterval: 10 * time.Second, @@ -79,6 +79,9 @@ var serverCmd = &cobra.Command{ PublicRootDomain: cfg.Space.PublicRootDomain, S3Internal: s3Internal, }) + if err != nil { + return fmt.Errorf("failed to init deploy: %w", err) + } r, err := router.NewRouter(cfg, enableSwagger) if err != nil { return fmt.Errorf("failed to init router: %w", err) diff --git a/cmd/csghub-server/cmd/sync/client.go b/cmd/csghub-server/cmd/sync/client.go index fe75057c..b2babe54 100644 --- a/cmd/csghub-server/cmd/sync/client.go +++ b/cmd/csghub-server/cmd/sync/client.go @@ -77,7 +77,7 @@ var cmdSyncAsClient = &cobra.Command{ syncClientSettingStore := database.NewSyncClientSettingStore() setting, err := syncClientSettingStore.First(ctx) if err != nil { - slog.Error("failed to find sync client setting, error: %w", err) + slog.Error("failed to find sync client setting", "error", err) return err } apiDomain := config.MultiSync.SaasAPIDomain diff --git a/cmd/csghub-server/cmd/sync/fix_default_branch.go b/cmd/csghub-server/cmd/sync/fix_default_branch.go index 99d09a80..0b168c2b 100644 --- a/cmd/csghub-server/cmd/sync/fix_default_branch.go +++ b/cmd/csghub-server/cmd/sync/fix_default_branch.go @@ -59,7 +59,7 @@ var cmdFixDefaultBranch = &cobra.Command{ for { repositories, err := repoStore.FindByRepoSourceWithBatch(ctx, types.OpenCSGSource, batchSize, batch) if err != nil { - slog.Error("failed to find repositories from OpenCSG, error: %w", err) + slog.Error("failed to find repositories from OpenCSG", "error", err) return } if len(repositories) == 0 { @@ -69,7 +69,7 @@ var cmdFixDefaultBranch = &cobra.Command{ syncClientSettingStore := database.NewSyncClientSettingStore() setting, err := syncClientSettingStore.First(ctx) if err != nil { - slog.Error("failed to find sync client setting, error: %w", err) + slog.Error("failed to find sync client setting", "error", err) return } apiDomain := config.MultiSync.SaasAPIDomain diff --git a/cmd/csghub-server/cmd/trigger/git_callback.go b/cmd/csghub-server/cmd/trigger/git_callback.go index c939d316..24fb4509 100644 --- a/cmd/csghub-server/cmd/trigger/git_callback.go +++ b/cmd/csghub-server/cmd/trigger/git_callback.go @@ -13,13 +13,12 @@ import ( "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/config" "opencsg.com/csghub-server/common/types" - "opencsg.com/csghub-server/component/callback" ) var ( - callbackComponent *callback.GitCallbackComponent - rs database.RepoStore - gs gitserver.GitServer + // callbackComponent *callback.GitCallbackComponent + rs database.RepoStore + gs gitserver.GitServer repoPaths []string ) diff --git a/cmd/csghub-server/cmd/trigger/init.go b/cmd/csghub-server/cmd/trigger/init.go index bba4824b..d78c63a9 100644 --- a/cmd/csghub-server/cmd/trigger/init.go +++ b/cmd/csghub-server/cmd/trigger/init.go @@ -7,7 +7,6 @@ import ( "opencsg.com/csghub-server/builder/git" "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/config" - "opencsg.com/csghub-server/component/callback" ) func init() { @@ -43,10 +42,6 @@ var Cmd = &cobra.Command{ if err != nil { return } - callbackComponent, err = callback.NewGitCallback(config) - if err != nil { - return - } return }, diff --git a/common/tests/testutils.go b/common/tests/testutils.go index d4a6308f..a5d6c6f6 100644 --- a/common/tests/testutils.go +++ b/common/tests/testutils.go @@ -76,7 +76,7 @@ func InitTestDB() *database.DB { } // switch to project root, so migrations can work correctly - os.Chdir("../../../") + _ = os.Chdir("../../../") bdb, err := newBun(ctx, database.DBConfig{ Dialect: database.DialectPostgres, DSN: dsn + "sslmode=disable", diff --git a/component/callback/git_callback.go b/component/callback/git_callback.go index 1568e7c7..7b51eba4 100644 --- a/component/callback/git_callback.go +++ b/component/callback/git_callback.go @@ -6,6 +6,7 @@ import ( "fmt" "log/slog" "path" + "strconv" "strings" "time" @@ -401,7 +402,11 @@ func (c *GitCallbackComponent) updateModelRuntimeFrameworks(ctx context.Context, //add resource tag, like ascend runtime_framework_tags, _ := c.ts.GetTagsByScopeAndCategories(ctx, "model", []string{"runtime_framework", "resource"}) fields := strings.Split(repo.Path, "/") - c.rac.AddResourceTag(ctx, runtime_framework_tags, fields[1], repo.ID) + err = c.rac.AddResourceTag(ctx, runtime_framework_tags, fields[1], repo.ID) + if err != nil { + slog.Warn("fail to add resource tag", slog.Any("error", err)) + return + } runtimes, err := c.ras.ListByRArchNameAndModel(ctx, arch, fields[1]) // to do check resource models if err != nil { @@ -420,9 +425,9 @@ func (c *GitCallbackComponent) updateModelRuntimeFrameworks(ctx context.Context, return } slog.Debug("get new frames by arch for git callback", slog.Any("namespace", namespace), slog.Any("repoName", repoName), slog.Any("newFrames", newFrames)) - var newFrameMap map[string]string = make(map[string]string) + var newFrameMap = make(map[string]string) for _, frame := range newFrames { - newFrameMap[string(frame.ID)] = string(frame.ID) + newFrameMap[strconv.FormatInt(frame.ID, 10)] = strconv.FormatInt(frame.ID, 10) } slog.Debug("get new frame map by arch for git callback", slog.Any("namespace", namespace), slog.Any("repoName", repoName), slog.Any("newFrameMap", newFrameMap)) oldRepoRuntimes, err := c.rrf.GetByRepoIDs(ctx, repo.ID) @@ -431,16 +436,16 @@ func (c *GitCallbackComponent) updateModelRuntimeFrameworks(ctx context.Context, return } slog.Debug("get old frames by arch for git callback", slog.Any("namespace", namespace), slog.Any("repoName", repoName), slog.Any("oldRepoRuntimes", oldRepoRuntimes)) - var oldFrameMap map[string]string = make(map[string]string) + var oldFrameMap = make(map[string]string) // get map for _, runtime := range oldRepoRuntimes { - oldFrameMap[string(runtime.RuntimeFrameworkID)] = string(runtime.RuntimeFrameworkID) + oldFrameMap[strconv.FormatInt(runtime.RuntimeFrameworkID, 10)] = strconv.FormatInt(runtime.RuntimeFrameworkID, 10) } slog.Debug("get old frame map by arch for git callback", slog.Any("namespace", namespace), slog.Any("repoName", repoName), slog.Any("oldFrameMap", oldFrameMap)) // remove incorrect relation for _, old := range oldRepoRuntimes { // check if it need remove - _, exist := newFrameMap[string(old.RuntimeFrameworkID)] + _, exist := newFrameMap[strconv.FormatInt(old.RuntimeFrameworkID, 10)] if !exist { // remove incorrect relations err := c.rrf.Delete(ctx, old.RuntimeFrameworkID, repo.ID, old.Type) @@ -455,7 +460,7 @@ func (c *GitCallbackComponent) updateModelRuntimeFrameworks(ctx context.Context, // add new relation for _, new := range newFrames { // check if it need add - _, exist := oldFrameMap[string(new.ID)] + _, exist := oldFrameMap[strconv.FormatInt(new.ID, 10)] if !exist { // add new relations err := c.rrf.Add(ctx, new.ID, repo.ID, new.Type) diff --git a/component/callback/repo_relation_watcher.go b/component/callback/repo_relation_watcher.go index 83afa623..f41872ee 100644 --- a/component/callback/repo_relation_watcher.go +++ b/component/callback/repo_relation_watcher.go @@ -77,7 +77,7 @@ func WatchRepoRelation(req *types.GiteaCallbackPushReq, ss database.RepoStore, func (w *repoRelationWatcher) Run() error { var err error for _, op := range w.ops { - errors.Join(err, op()) + err = errors.Join(err, op()) } return err } diff --git a/component/callback/space_deploy_watcher.go b/component/callback/space_deploy_watcher.go index f0a07ccf..0525b8fe 100644 --- a/component/callback/space_deploy_watcher.go +++ b/component/callback/space_deploy_watcher.go @@ -38,7 +38,7 @@ func WatchSpaceChange(req *types.GiteaCallbackPushReq, ss database.SpaceStore, s func (w *spaceDeployWatcher) Run() error { var err error for _, op := range w.ops { - errors.Join(err, op()) + err = errors.Join(err, op()) } return err } diff --git a/component/git_http.go b/component/git_http.go index 62b2743a..b8dbc112 100644 --- a/component/git_http.go +++ b/component/git_http.go @@ -192,9 +192,6 @@ func (c *gitHTTPComponentImpl) BuildObjectResponse(ctx context.Context, req type objectKey := path.Join("lfs", obj.RelativePath()) _, err := c.s3Client.StatObject(ctx, c.config.S3.Bucket, objectKey, minio.StatObjectOptions{}) if err != nil { - if os.IsNotExist(err) { - exists = false - } slog.Error("failed to check if lfs file exists", slog.String("oid", objectKey), slog.Any("error", err)) exists = false } else { @@ -346,7 +343,7 @@ func (c *gitHTTPComponentImpl) LfsUpload(ctx context.Context, body io.ReadCloser hash := sha256.New() written, err := io.Copy(hash, body) if err != nil { - slog.Error("Error creating hash. Error: %v", err) + slog.Error("Error creating hash. Error", "error", err) return err } diff --git a/component/list.go b/component/list.go index 46b4a6c0..3567692b 100644 --- a/component/list.go +++ b/component/list.go @@ -33,7 +33,7 @@ func (c *listComponentImpl) ListModelsByPath(ctx context.Context, req *types.Lis models, err := c.ms.ListByPath(ctx, req.Paths) if err != nil { - slog.Error("error listing models by path: %v", err, slog.Any("paths", req.Paths)) + slog.Error("error listing models by path", "error", err, slog.Any("paths", req.Paths)) return nil, err } for _, model := range models { @@ -69,7 +69,7 @@ func (c *listComponentImpl) ListDatasetsByPath(ctx context.Context, req *types.L datasets, err := c.ds.ListByPath(ctx, req.Paths) if err != nil { - slog.Error("error listing datasets by path: %v", err, slog.Any("paths", req.Paths)) + slog.Error("error listing datasets by path", "error", err, slog.Any("paths", req.Paths)) return nil, err } for _, dataset := range datasets { diff --git a/component/mirror.go b/component/mirror.go index 20f9e88f..399d2f43 100644 --- a/component/mirror.go +++ b/component/mirror.go @@ -286,7 +286,7 @@ func (c *mirrorComponentImpl) CreateMirrorRepo(ctx context.Context, req types.Cr } func (m *mirrorComponentImpl) mapNamespaceAndName(sourceNamespace string) string { - namespace := sourceNamespace + var namespace string if ns, found := mirrorOrganizationMap[sourceNamespace]; found { namespace = ns } else { diff --git a/component/multi_sync.go b/component/multi_sync.go index 22c287d0..38e2494d 100644 --- a/component/multi_sync.go +++ b/component/multi_sync.go @@ -81,8 +81,6 @@ func (c *multiSyncComponentImpl) SyncAsClient(ctx context.Context, sc multisync. if err != nil { if err != sql.ErrNoRows { return fmt.Errorf("failed to get latest sync version from db: %w", err) - } else { - currentVersion = 0 } } diff --git a/component/recom.go b/component/recom.go index 6c344abf..c3661891 100644 --- a/component/recom.go +++ b/component/recom.go @@ -51,12 +51,12 @@ func (rc *recomComponentImpl) SetOpWeight(ctx context.Context, repoID, weight in func (rc *recomComponentImpl) CalculateRecomScore(ctx context.Context) { weights, err := rc.loadWeights() if err != nil { - slog.Error("Error loading weights", err) + slog.Error("Error loading weights", "error", err) return } repos, err := rc.repos.All(ctx) if err != nil { - slog.Error("Error fetching repositories", err) + slog.Error("Error fetching repositories", "error", err) return } for _, repo := range repos { @@ -95,13 +95,13 @@ func (rc *recomComponentImpl) calcFreshnessScore(createdAt time.Time, weightExp // TODO:cache compiled script hours := time.Since(createdAt).Hours() scriptFreshness := tengo.NewScript([]byte(weightExp)) - scriptFreshness.Add("score", 0.0) - scriptFreshness.Add("hours", 0) + _ = scriptFreshness.Add("score", 0.0) + _ = scriptFreshness.Add("hours", 0) sc, err := scriptFreshness.Compile() if err != nil { panic(err) } - sc.Set("hours", hours) + _ = sc.Set("hours", hours) err = sc.Run() if err != nil { panic(err) @@ -113,13 +113,13 @@ func (rc *recomComponentImpl) calcFreshnessScore(createdAt time.Time, weightExp func (rc *recomComponentImpl) calcDownloadsScore(downloads int64, weightExp string) float64 { // TODO:cache compiled script scriptFreshness := tengo.NewScript([]byte(weightExp)) - scriptFreshness.Add("score", 0.0) - scriptFreshness.Add("downloads", 0) + _ = scriptFreshness.Add("score", 0.0) + _ = scriptFreshness.Add("downloads", 0) sc, err := scriptFreshness.Compile() if err != nil { panic(err) } - sc.Set("downloads", downloads) + _ = sc.Set("downloads", downloads) err = sc.Run() if err != nil { panic(err) @@ -169,16 +169,16 @@ func (rc *recomComponentImpl) loadWeights() (map[string]string, error) { return weights, nil } -func (rc *recomComponentImpl) loadOpWeights() (map[int64]int, error) { - ctx := context.Background() - items, err := rc.rs.LoadOpWeights(ctx) - if err != nil { - return nil, err - } - - weights := make(map[int64]int) - for _, item := range items { - weights[item.RepositoryID] = item.Weight - } - return weights, nil -} +// func (rc *recomComponentImpl) loadOpWeights() (map[int64]int, error) { +// ctx := context.Background() +// items, err := rc.rs.LoadOpWeights(ctx) +// if err != nil { +// return nil, err +// } + +// weights := make(map[int64]int) +// for _, item := range items { +// weights[item.RepositoryID] = item.Weight +// } +// return weights, nil +// } diff --git a/component/recom_test.go b/component/recom_test.go index dcd2cc0d..c238f0b2 100644 --- a/component/recom_test.go +++ b/component/recom_test.go @@ -61,14 +61,14 @@ if hours <= 48{ } ` -const expDownloads = ` -if downloads <= 10{ - score = downloads * (10 / 10) -}else if downloads <= 100{ - score = 10 + (downloads - 10) * (40.0 / 90.0) -}else if downloads <= 1000{ - score = 50 + (downloads - 100) * (40.0 / 900.0) -}else{ - score = 90 + 10 * (1 - (1 / (downloads / 1000.0))) -} -` +// const expDownloads = ` +// if downloads <= 10{ +// score = downloads * (10 / 10) +// }else if downloads <= 100{ +// score = 10 + (downloads - 10) * (40.0 / 90.0) +// }else if downloads <= 1000{ +// score = 50 + (downloads - 100) * (40.0 / 900.0) +// }else{ +// score = 90 + 10 * (1 - (1 / (downloads / 1000.0))) +// } +// ` diff --git a/component/repo.go b/component/repo.go index fdf71fa0..553e2ed1 100644 --- a/component/repo.go +++ b/component/repo.go @@ -1113,10 +1113,6 @@ func (c *repoComponentImpl) Tree(ctx context.Context, req *types.GetFileReq) ([] } func (c *repoComponentImpl) UploadFile(ctx context.Context, req *types.CreateFileReq) error { - parentPath := filepath.Dir(req.FilePath) - if parentPath == "." { - parentPath = "/" - } f, err := c.git.GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: req.Namespace, Name: req.Name, @@ -2049,8 +2045,8 @@ func (c *repoComponentImpl) DeleteDeploy(ctx context.Context, delReq types.Deplo func (c *repoComponentImpl) DeployDetail(ctx context.Context, detailReq types.DeployActReq) (*types.DeployRepo, error) { var ( - deploy *database.Deploy = nil - err error = nil + deploy *database.Deploy + err error ) if detailReq.DeployType == types.ServerlessType { _, deploy, err = c.checkDeployPermissionForServerless(ctx, detailReq) @@ -2195,8 +2191,8 @@ func deployStatusCodeToString(code int) string { func (c *repoComponentImpl) DeployInstanceLogs(ctx context.Context, logReq types.DeployActReq) (*deploy.MultiLogReader, error) { var ( - deploy *database.Deploy = nil - err error = nil + deploy *database.Deploy + err error ) if logReq.DeployType == types.ServerlessType { _, deploy, err = c.checkDeployPermissionForServerless(ctx, logReq) @@ -2299,9 +2295,9 @@ func (c *repoComponentImpl) checkAccessDeployForServerless(ctx context.Context, func (c *repoComponentImpl) DeployStop(ctx context.Context, stopReq types.DeployActReq) error { var ( - user *database.User = nil - deploy *database.Deploy = nil - err error = nil + user *database.User + deploy *database.Deploy + err error ) if stopReq.DeployType == types.ServerlessType { user, deploy, err = c.checkDeployPermissionForServerless(ctx, stopReq) @@ -2486,8 +2482,8 @@ func (c *repoComponentImpl) checkDeployPermissionForServerless(ctx context.Conte func (c *repoComponentImpl) DeployUpdate(ctx context.Context, updateReq types.DeployActReq, req *types.DeployUpdateReq) error { var ( - deploy *database.Deploy = nil - err error = nil + deploy *database.Deploy + err error ) if updateReq.DeployType == types.ServerlessType { _, deploy, err = c.checkDeployPermissionForServerless(ctx, updateReq) @@ -2541,8 +2537,8 @@ func (c *repoComponentImpl) DeployUpdate(ctx context.Context, updateReq types.De func (c *repoComponentImpl) DeployStart(ctx context.Context, startReq types.DeployActReq) error { var ( - deploy *database.Deploy = nil - err error = nil + deploy *database.Deploy + err error ) if startReq.DeployType == types.ServerlessType { _, deploy, err = c.checkDeployPermissionForServerless(ctx, startReq) diff --git a/component/space.go b/component/space.go index 0b447d42..dc9a6baa 100644 --- a/component/space.go +++ b/component/space.go @@ -585,7 +585,7 @@ func (c *spaceComponentImpl) Delete(ctx context.Context, namespace, name, curren } // stop any running space instance - go c.Stop(ctx, namespace, name) + go func() { _ = c.Stop(ctx, namespace, name) }() return nil } @@ -703,7 +703,9 @@ func (c *spaceComponentImpl) FixHasEntryFile(ctx context.Context, s *database.Sp hasAppFile := c.HasEntryFile(ctx, s) if s.HasAppFile != hasAppFile { s.HasAppFile = hasAppFile - c.ss.Update(ctx, *s) + if er := c.ss.Update(ctx, *s); er != nil { + slog.Error("update space failed", "error", er) + } } return s diff --git a/component/user.go b/component/user.go index c3146a8a..72e9ef6f 100644 --- a/component/user.go +++ b/component/user.go @@ -93,7 +93,7 @@ type userComponentImpl struct { deploy database.DeployTaskStore cos database.CollectionStore ac AccountingComponent - srs database.SpaceResourceStore + // srs database.SpaceResourceStore // urs *database.UserResourcesStore pt database.PromptStore } @@ -550,7 +550,7 @@ func (c *userComponentImpl) ListDeploys(ctx context.Context, repoType types.Repo endpoint, _ := c.repoComponent.generateEndpoint(ctx, d) repoPath := strings.TrimPrefix(deploy.GitPath, string(repoType)+"s_") var hardware types.HardWare - json.Unmarshal([]byte(deploy.Hardware), &hardware) + _ = json.Unmarshal([]byte(deploy.Hardware), &hardware) resourceType := "" if hardware.Gpu.Num != "" { resourceType = hardware.Gpu.Type diff --git a/mirror/queue/queue.go b/mirror/queue/queue.go index 696392c1..97a6dcc6 100644 --- a/mirror/queue/queue.go +++ b/mirror/queue/queue.go @@ -58,7 +58,7 @@ func (mq *MirrorQueue) Push(t *MirrorTask) { if t.CreatedAt == 0 { t.CreatedAt = time.Now().Unix() } - mq.redis.ZAdd(context.Background(), mq.QueueName, redis.Z{ + _ = mq.redis.ZAdd(context.Background(), mq.QueueName, redis.Z{ Score: float64(t.CreatedAt) * float64(t.Priority), Member: t, }) @@ -70,7 +70,7 @@ func (mq *MirrorQueue) Pop() *MirrorTask { return nil } var task MirrorTask - json.Unmarshal([]byte(r.Member.(string)), &task) + _ = json.Unmarshal([]byte(r.Member.(string)), &task) return &task } diff --git a/moderation/component/repo.go b/moderation/component/repo.go index 4a2b74f3..86b2bc21 100644 --- a/moderation/component/repo.go +++ b/moderation/component/repo.go @@ -111,7 +111,10 @@ func (c *repoComponentImpl) processFile(ctx context.Context, file *database.Repo slog.String("err", msg)) } - c.saveCheckResult(ctx, file, status, msg) + err := c.saveCheckResult(ctx, file, status, msg) + if err != nil { + slog.Error("save check result failed", "error", err) + } } func (c *repoComponentImpl) saveCheckResult(ctx context.Context, file *database.RepositoryFile, status types.SensitiveCheckStatus, msg string) error { diff --git a/servicerunner/handler/k8s.go b/servicerunner/handler/k8s.go index e23811f2..2ac760a3 100644 --- a/servicerunner/handler/k8s.go +++ b/servicerunner/handler/k8s.go @@ -70,7 +70,11 @@ func (s *K8sHander) RunService(c *gin.Context) { // check if the ksvc exists _, err = cluster.KnativeClient.ServingV1().Services(s.k8sNameSpace).Get(c.Request.Context(), srvName, metav1.GetOptions{}) if err == nil { - s.removeServiceForcely(c, cluster, srvName) + err = s.removeServiceForcely(c, cluster, srvName) + if err != nil { + slog.Error("fail to remove service", slog.Any("error", err), slog.Any("req", request)) + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + } slog.Info("service already exists,delete it first", slog.String("srv_name", srvName), slog.Any("image_id", request.ImageID)) } service, err := s.s.GenerateService(c, *cluster, *request, srvName) @@ -500,7 +504,10 @@ func (s *K8sHander) GetLogsByPod(c *gin.Context, cluster cluster.Cluster, podNam for _, condition := range pod.Status.Conditions { if condition.Type == "PodScheduled" && condition.Status == "False" { message := fmt.Sprintf("Pod is pending due to reason: %s, message: %s", condition.Reason, condition.Message) - c.Writer.Write([]byte(message)) + _, err = c.Writer.Write([]byte(message)) + if err != nil { + slog.Error("write data failed", "error", err) + } c.Writer.Flush() c.JSON(http.StatusBadRequest, gin.H{"error": message}) return @@ -524,7 +531,10 @@ func (s *K8sHander) GetLogsByPod(c *gin.Context, cluster cluster.Cluster, podNam } if n > 0 { - c.Writer.Write(buf[:n]) + _, err = c.Writer.Write(buf[:n]) + if err != nil { + slog.Error("write data failed", "error", err) + } c.Writer.Flush() slog.Info("send pod logs", slog.String("srv_name", srvName), slog.String("srv_name", srvName), slog.Int("len", n), slog.String("log", string(buf[:n]))) } diff --git a/user/component/user.go b/user/component/user.go index a541c1d7..0d1bfa28 100644 --- a/user/component/user.go +++ b/user/component/user.go @@ -107,11 +107,11 @@ func NewUserComponent(config *config.Config) (UserComponent, error) { return c, nil } -// This function creates a user when user register from portal, without casdoor -func (c *userComponentImpl) createFromPortalRegistry(ctx context.Context, req types.CreateUserRequest) (*database.User, error) { - // Panic if the function has not been implemented - panic("implement me later") -} +// // This function creates a user when user register from portal, without casdoor +// func (c *userComponentImpl) createFromPortalRegistry(ctx context.Context, req types.CreateUserRequest) (*database.User, error) { +// // Panic if the function has not been implemented +// panic("implement me later") +// } func (c *userComponentImpl) createFromCasdoorUser(ctx context.Context, cu casdoorsdk.User) (*database.User, error) { var ( @@ -355,9 +355,9 @@ func (c *userComponentImpl) Delete(ctx context.Context, operator, username strin } slog.Debug("delete user from git server", slog.String("operator", operator), slog.String("username", user.Username)) - if c.config.GitServer.Type == types.GitServerTypeGitea { - // gitea gitserver does not support delete user, you could create a pr to our repo to fix it - } + // if c.config.GitServer.Type == types.GitServerTypeGitea { + // // gitea gitserver does not support delete user, you could create a pr to our repo to fix it + // } if c.config.GitServer.Type == types.GitServerTypeGitaly { repos, err := c.repo.ByUser(ctx, user.ID)