diff --git a/src/.golangci.yaml b/src/.golangci.yaml index 3a380668b..252639f59 100644 --- a/src/.golangci.yaml +++ b/src/.golangci.yaml @@ -29,7 +29,7 @@ linters: # - whitespace - bodyclose - deadcode - # - errcheck + - errcheck # - gosec # - gosimple - govet @@ -48,7 +48,7 @@ run: - ".*_test.go" - ".*test.go" skip-dirs: - - "testing/" + - "testing" timeout: 5m issue: diff --git a/src/chartserver/chart_operator.go b/src/chartserver/chart_operator.go index c4f2ba09a..91dcc5053 100644 --- a/src/chartserver/chart_operator.go +++ b/src/chartserver/chart_operator.go @@ -87,11 +87,13 @@ func (cho *ChartOperator) GetChartDetails(content []byte) (*ChartVersionDetails, if len(chartData.Values) > 0 { c := chartutil.Values(chartData.Values) ValYaml, err := c.YAML() - if err != nil { return nil, err } - c.Encode(&buf) + err = c.Encode(&buf) + if err != nil { + return nil, err + } values = parseRawValues(buf.Bytes()) // Append values.yaml file files[valuesFileName] = ValYaml diff --git a/src/chartserver/redis_sentinel.go b/src/chartserver/redis_sentinel.go index 7017d1c11..f7f9ff11f 100644 --- a/src/chartserver/redis_sentinel.go +++ b/src/chartserver/redis_sentinel.go @@ -132,7 +132,10 @@ func (rc *Cache) ClearAll() error { // so no gc operation. func (rc *Cache) StartAndGC(config string) error { var cf map[string]string - json.Unmarshal([]byte(config), &cf) + err := json.Unmarshal([]byte(config), &cf) + if err != nil { + return err + } if _, ok := cf["key"]; !ok { cf["key"] = DefaultKey diff --git a/src/common/job/test/server.go b/src/common/job/test/server.go index 2f91429df..be8ce442d 100644 --- a/src/common/job/test/server.go +++ b/src/common/job/test/server.go @@ -14,6 +14,7 @@ import ( "github.com/goharbor/harbor/src/common/job/models" "github.com/goharbor/harbor/src/jobservice/job" job_models "github.com/goharbor/harbor/src/jobservice/job" + "github.com/goharbor/harbor/src/lib/log" ) const ( @@ -99,7 +100,10 @@ func NewJobServiceServer() *httptest.Server { panic(err) } jobReq := models.JobRequest{} - json.Unmarshal(data, &jobReq) + err = json.Unmarshal(data, &jobReq) + if err != nil { + log.Warningf("failed to unmarshal json to models.JobRequest, error: %v", err) + } if jobReq.Job.Name == "replication" { respData := models.JobStats{ Stats: &models.StatsInfo{ diff --git a/src/controller/blob/controller.go b/src/controller/blob/controller.go index 3746a1417..a0d53ed24 100644 --- a/src/controller/blob/controller.go +++ b/src/controller/blob/controller.go @@ -295,7 +295,7 @@ func (c *controller) Sync(ctx context.Context, references []distribution.Descrip } if len(updating) > 0 { - orm.WithTransaction(func(ctx context.Context) error { + err := orm.WithTransaction(func(ctx context.Context) error { for _, blob := range updating { if err := c.Update(ctx, blob); err != nil { log.G(ctx).Warningf("Failed to update blob %s, error: %v", blob.Digest, err) @@ -305,6 +305,9 @@ func (c *controller) Sync(ctx context.Context, references []distribution.Descrip return nil })(orm.SetTransactionOpNameToContext(ctx, "tx-sync-blob")) + if err != nil { + return err + } } if len(missing) > 0 { diff --git a/src/controller/event/handler/init.go b/src/controller/event/handler/init.go index 0df44d765..12ea88dfa 100644 --- a/src/controller/event/handler/init.go +++ b/src/controller/event/handler/init.go @@ -21,47 +21,47 @@ import ( func init() { // notification - notifier.Subscribe(event.TopicPushArtifact, &artifact.Handler{}) - notifier.Subscribe(event.TopicPullArtifact, &artifact.Handler{}) - notifier.Subscribe(event.TopicDeleteArtifact, &artifact.Handler{}) - notifier.Subscribe(event.TopicUploadChart, &chart.Handler{}) - notifier.Subscribe(event.TopicDeleteChart, &chart.Handler{}) - notifier.Subscribe(event.TopicDownloadChart, &chart.Handler{}) - notifier.Subscribe(event.TopicQuotaExceed, "a.Handler{}) - notifier.Subscribe(event.TopicQuotaWarning, "a.Handler{}) - notifier.Subscribe(event.TopicScanningFailed, &scan.Handler{}) - notifier.Subscribe(event.TopicScanningStopped, &scan.Handler{}) - notifier.Subscribe(event.TopicScanningCompleted, &scan.Handler{}) - notifier.Subscribe(event.TopicDeleteArtifact, &scan.DelArtHandler{}) - notifier.Subscribe(event.TopicReplication, &artifact.ReplicationHandler{}) - notifier.Subscribe(event.TopicTagRetention, &artifact.RetentionHandler{}) + _ = notifier.Subscribe(event.TopicPushArtifact, &artifact.Handler{}) + _ = notifier.Subscribe(event.TopicPullArtifact, &artifact.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteArtifact, &artifact.Handler{}) + _ = notifier.Subscribe(event.TopicUploadChart, &chart.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteChart, &chart.Handler{}) + _ = notifier.Subscribe(event.TopicDownloadChart, &chart.Handler{}) + _ = notifier.Subscribe(event.TopicQuotaExceed, "a.Handler{}) + _ = notifier.Subscribe(event.TopicQuotaWarning, "a.Handler{}) + _ = notifier.Subscribe(event.TopicScanningFailed, &scan.Handler{}) + _ = notifier.Subscribe(event.TopicScanningStopped, &scan.Handler{}) + _ = notifier.Subscribe(event.TopicScanningCompleted, &scan.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteArtifact, &scan.DelArtHandler{}) + _ = notifier.Subscribe(event.TopicReplication, &artifact.ReplicationHandler{}) + _ = notifier.Subscribe(event.TopicTagRetention, &artifact.RetentionHandler{}) // replication - notifier.Subscribe(event.TopicPushArtifact, &replication.Handler{}) - notifier.Subscribe(event.TopicDeleteArtifact, &replication.Handler{}) - notifier.Subscribe(event.TopicCreateTag, &replication.Handler{}) - notifier.Subscribe(event.TopicDeleteTag, &replication.Handler{}) + _ = notifier.Subscribe(event.TopicPushArtifact, &replication.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteArtifact, &replication.Handler{}) + _ = notifier.Subscribe(event.TopicCreateTag, &replication.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteTag, &replication.Handler{}) // p2p preheat - notifier.Subscribe(event.TopicPushArtifact, &p2p.Handler{}) - notifier.Subscribe(event.TopicScanningCompleted, &p2p.Handler{}) - notifier.Subscribe(event.TopicArtifactLabeled, &p2p.Handler{}) + _ = notifier.Subscribe(event.TopicPushArtifact, &p2p.Handler{}) + _ = notifier.Subscribe(event.TopicScanningCompleted, &p2p.Handler{}) + _ = notifier.Subscribe(event.TopicArtifactLabeled, &p2p.Handler{}) // audit logs - notifier.Subscribe(event.TopicPushArtifact, &auditlog.Handler{}) - notifier.Subscribe(event.TopicPullArtifact, &auditlog.Handler{}) - notifier.Subscribe(event.TopicDeleteArtifact, &auditlog.Handler{}) - notifier.Subscribe(event.TopicCreateProject, &auditlog.Handler{}) - notifier.Subscribe(event.TopicDeleteProject, &auditlog.Handler{}) - notifier.Subscribe(event.TopicDeleteRepository, &auditlog.Handler{}) - notifier.Subscribe(event.TopicCreateTag, &auditlog.Handler{}) - notifier.Subscribe(event.TopicDeleteTag, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicPushArtifact, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicPullArtifact, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteArtifact, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicCreateProject, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteProject, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteRepository, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicCreateTag, &auditlog.Handler{}) + _ = notifier.Subscribe(event.TopicDeleteTag, &auditlog.Handler{}) // internal - notifier.Subscribe(event.TopicPullArtifact, &internal.Handler{}) - notifier.Subscribe(event.TopicPushArtifact, &internal.Handler{}) + _ = notifier.Subscribe(event.TopicPullArtifact, &internal.Handler{}) + _ = notifier.Subscribe(event.TopicPushArtifact, &internal.Handler{}) - task.RegisterTaskStatusChangePostFunc(job.Replication, func(ctx context.Context, taskID int64, status string) error { + _ = task.RegisterTaskStatusChangePostFunc(job.Replication, func(ctx context.Context, taskID int64, status string) error { notification.AddEvent(ctx, &metadata.ReplicationMetaData{ ReplicationTaskID: taskID, Status: status, diff --git a/src/controller/gc/callback.go b/src/controller/gc/callback.go index 8a9cfaf92..6f8907571 100644 --- a/src/controller/gc/callback.go +++ b/src/controller/gc/callback.go @@ -51,7 +51,10 @@ func gcCallback(ctx context.Context, p string) error { func gcTaskStatusChange(ctx context.Context, taskID int64, status string) error { if status == job.SuccessStatus.String() && config.QuotaPerProjectEnable(ctx) { go func() { - quota.RefreshForProjects(orm.Context()) + err := quota.RefreshForProjects(orm.Context()) + if err != nil { + log.Warningf("failed to refresh project quota, error: %v", err) + } }() } diff --git a/src/controller/replication/policy.go b/src/controller/replication/policy.go index 55aaa0c54..d951f70d4 100644 --- a/src/controller/replication/policy.go +++ b/src/controller/replication/policy.go @@ -70,7 +70,10 @@ func (c *controller) ListPolicies(ctx context.Context, query *q.Query) ([]*model func (c *controller) populateRegistry(ctx context.Context, p *pkgmodel.Policy) (*model.Policy, error) { policy := &model.Policy{} - policy.From(p) + err := policy.From(p) + if err != nil { + return nil, err + } var srcRegistryID, destRegistryID int64 = 0, 0 if policy.SrcRegistry != nil && policy.SrcRegistry.ID != 0 { srcRegistryID = policy.SrcRegistry.ID diff --git a/src/controller/scan/base_controller.go b/src/controller/scan/base_controller.go index 708c5fe70..4fbd13f97 100644 --- a/src/controller/scan/base_controller.go +++ b/src/controller/scan/base_controller.go @@ -362,7 +362,8 @@ func (bc *basicController) ScanAll(ctx context.Context, trigger string, async bo return } - bc.startScanAll(ctx, executionID) + err = bc.startScanAll(ctx, executionID) + log.Errorf("failed to start scan all, executionID=%d, error: %v", executionID, err) }(bc.makeCtx()) } else { if err := bc.startScanAll(ctx, executionID); err != nil { diff --git a/src/controller/scanner/options.go b/src/controller/scanner/options.go index 426784bc1..17af3954a 100644 --- a/src/controller/scanner/options.go +++ b/src/controller/scanner/options.go @@ -41,7 +41,7 @@ func newOptions(options ...Option) *Options { opts := &Options{Ping: true} for _, o := range options { - o(opts) + _ = o(opts) } return opts diff --git a/src/core/api/base.go b/src/core/api/base.go index 7c012a6a3..afbc552c7 100644 --- a/src/core/api/base.go +++ b/src/core/api/base.go @@ -155,7 +155,12 @@ func (b *BaseController) WriteYamlData(object interface{}) { // PopulateUserSession generates a new session ID and fill the user model in parm to the session func (b *BaseController) PopulateUserSession(u models.User) { - b.SessionRegenerateID() + err := b.SessionRegenerateID() + if err != nil { + log.Errorf("failed to generate a new session ID and fill the user mode to this session, error: %v", err) + b.SendError(err) + return + } b.SetSession(userSessionKey, u) } diff --git a/src/core/api/internal.go b/src/core/api/internal.go index f36117a3e..0c240b06e 100644 --- a/src/core/api/internal.go +++ b/src/core/api/internal.go @@ -80,14 +80,20 @@ func (ia *InternalAPI) SyncQuota() { cfgMgr := config.GetCfgManager(ctx) if !cur { cfgMgr.Set(ctx, common.ReadOnly, true) - cfgMgr.Save(ctx) + err := cfgMgr.Save(ctx) + if err != nil { + log.Warningf("failed to save context into config manager, error: %v", err) + } } // For api call, to avoid the timeout, it should be asynchronous go func() { defer func() { ctx := orm.Context() cfgMgr.Set(ctx, common.ReadOnly, cur) - cfgMgr.Save(ctx) + err := cfgMgr.Save(ctx) + if err != nil { + log.Warningf("failed to save context into config manager asynchronously, error: %v", err) + } }() log.Info("start to sync quota(API), the system will be set to ReadOnly and back it normal once it done.") ctx := orm.NewContext(context.TODO(), o.NewOrm()) diff --git a/src/core/controllers/base.go b/src/core/controllers/base.go index 8c8c9da69..cd8242e1f 100644 --- a/src/core/controllers/base.go +++ b/src/core/controllers/base.go @@ -83,9 +83,12 @@ func (cc *CommonController) Login() { log.Debugf("Redirect user %s to login page of OIDC provider", principal) // Return a json to UI with status code 403, as it cannot handle status 302 cc.Ctx.Output.Status = http.StatusForbidden - cc.Ctx.Output.JSON(struct { + err = cc.Ctx.Output.JSON(struct { Location string `json:"redirect_location"` }{url}, false, false) + if err != nil { + log.Errorf("Failed to write json to response body, error: %v", err) + } return } diff --git a/src/core/main.go b/src/core/main.go index 2d4956feb..de4133f48 100755 --- a/src/core/main.go +++ b/src/core/main.go @@ -223,7 +223,10 @@ func main() { log.Infof("Version: %s, Git commit: %s", version.ReleaseVersion, version.GitCommit) log.Info("Fix empty subiss for meta info data.") - oidc.FixEmptySubIss(orm.Context()) + _, err = oidc.FixEmptySubIss(orm.Context()) + if err != nil { + log.Warningf("oidc.FixEmptySubIss() errors out, error: %v", err) + } beego.RunWithMiddleWares("", middlewares.MiddleWares()...) } diff --git a/src/core/session/session.go b/src/core/session/session.go index ec09f7f40..825259acb 100644 --- a/src/core/session/session.go +++ b/src/core/session/session.go @@ -136,7 +136,10 @@ func (rp *Provider) SessionExist(sid string) bool { func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) { ctx := context.TODO() if !rp.SessionExist(oldsid) { - rp.c.Save(ctx, sid, "", time.Duration(rp.maxlifetime)) + err := rp.c.Save(ctx, sid, "", time.Duration(rp.maxlifetime)) + if err != nil { + log.Warningf("failed to save sid=%s, where oldsid=%s, error: %s", sid, oldsid, err) + } } else { if rdb, ok := rp.c.(*redis.Cache); ok { // redis has rename command @@ -149,8 +152,14 @@ func (rp *Provider) SessionRegenerate(oldsid, sid string) (session.Store, error) return nil, err } - rp.c.Delete(ctx, oldsid) - rp.c.Save(ctx, sid, kv) + err = rp.c.Delete(ctx, oldsid) + if err != nil { + log.Warningf("failed to delete oldsid=%s, error: %s", oldsid, err) + } + err = rp.c.Save(ctx, sid, kv) + if err != nil { + log.Warningf("failed to save sid=%s, error: %s", sid, err) + } } } diff --git a/src/jobservice/job/impl/context.go b/src/jobservice/job/impl/context.go index 17c29188d..7f3152729 100644 --- a/src/jobservice/job/impl/context.go +++ b/src/jobservice/job/impl/context.go @@ -91,7 +91,11 @@ func (c *Context) Init() error { } // Initialize DB finished - initDBCompleted() + err = initDBCompleted() + if err != nil { + logger.Errorf("failed to call initDBCompleted(), error: %v", err) + return err + } return nil } @@ -216,6 +220,5 @@ func createLoggers(jobID string) (logger.Interface, error) { } func initDBCompleted() error { - sweeper.PrepareDBSweep() - return nil + return sweeper.PrepareDBSweep() } diff --git a/src/jobservice/job/impl/sample/job.go b/src/jobservice/job/impl/sample/job.go index afb72d990..a84c04fe9 100644 --- a/src/jobservice/job/impl/sample/job.go +++ b/src/jobservice/job/impl/sample/job.go @@ -80,9 +80,9 @@ func (j *Job) Run(ctx job.Context, params job.Parameters) error { return errors.New("`JOB_FAILED` env is set") } - ctx.Checkin("progress data: %30") + _ = ctx.Checkin("progress data: %30") <-time.After(1 * time.Second) - ctx.Checkin("progress data: %60") + _ = ctx.Checkin("progress data: %60") // HOLD ON FOR A WHILE logger.Warning("Holding for 30 seconds") diff --git a/src/jobservice/main.go b/src/jobservice/main.go index be56e7abf..e9670d9d8 100644 --- a/src/jobservice/main.go +++ b/src/jobservice/main.go @@ -35,7 +35,9 @@ import ( func main() { cfgLib.DefaultCfgManager = common.RestCfgManager - cfgLib.DefaultMgr().Load(context.Background()) + if err := cfgLib.DefaultMgr().Load(context.Background()); err != nil { + panic(fmt.Sprintf("failed to load configuration, error: %v", err)) + } // Get parameters configPath := flag.String("c", "", "Specify the yaml config file path") diff --git a/src/lib/cache/memory/memory.go b/src/lib/cache/memory/memory.go index 4941b34ae..f32f1af78 100644 --- a/src/lib/cache/memory/memory.go +++ b/src/lib/cache/memory/memory.go @@ -23,6 +23,7 @@ import ( "time" "github.com/goharbor/harbor/src/lib/cache" + "github.com/goharbor/harbor/src/lib/log" ) type entry struct { @@ -50,7 +51,8 @@ func (c *Cache) Contains(ctx context.Context, key string) bool { } if e.(*entry).isExpirated() { - c.Delete(ctx, c.opts.Key(key)) + err := c.Delete(ctx, c.opts.Key(key)) + log.Errorf("failed to delete cache in Contains() method when it's expired, error: %v", err) return false } @@ -72,7 +74,8 @@ func (c *Cache) Fetch(ctx context.Context, key string, value interface{}) error e := v.(*entry) if e.isExpirated() { - c.Delete(ctx, c.opts.Key(key)) + err := c.Delete(ctx, c.opts.Key(key)) + log.Errorf("failed to delete cache in Fetch() method when it's expired, error: %v", err) return cache.ErrNotFound } diff --git a/src/lib/config/config.go b/src/lib/config/config.go index 23c04062c..55446b634 100644 --- a/src/lib/config/config.go +++ b/src/lib/config/config.go @@ -102,7 +102,10 @@ func InitWithSettings(cfgs map[string]interface{}, kp ...encrypt.KeyProvider) { Init() DefaultCfgManager = common.InMemoryCfgManager mgr := DefaultMgr() - mgr.UpdateConfig(backgroundCtx, cfgs) + err := mgr.UpdateConfig(backgroundCtx, cfgs) + if err != nil { + log.Warningf("failed to update config, error: %v", err) + } if len(kp) > 0 { keyProvider = kp[0] } diff --git a/src/lib/log/logger.go b/src/lib/log/logger.go index 356dc4d09..a3d0fe8dd 100644 --- a/src/lib/log/logger.go +++ b/src/lib/log/logger.go @@ -188,7 +188,7 @@ func (l *Logger) output(record *Record) (err error) { func (l *Logger) Debug(v ...interface{}) { if l.lvl <= DebugLevel { record := NewRecord(time.Now(), fmt.Sprint(v...), l.getLine(), DebugLevel) - l.output(record) + _ = l.output(record) } } @@ -196,7 +196,7 @@ func (l *Logger) Debug(v ...interface{}) { func (l *Logger) Debugf(format string, v ...interface{}) { if l.lvl <= DebugLevel { record := NewRecord(time.Now(), fmt.Sprintf(format, v...), l.getLine(), DebugLevel) - l.output(record) + _ = l.output(record) } } @@ -204,7 +204,7 @@ func (l *Logger) Debugf(format string, v ...interface{}) { func (l *Logger) Info(v ...interface{}) { if l.lvl <= InfoLevel { record := NewRecord(time.Now(), fmt.Sprint(v...), l.getLine(), InfoLevel) - l.output(record) + _ = l.output(record) } } @@ -212,7 +212,7 @@ func (l *Logger) Info(v ...interface{}) { func (l *Logger) Infof(format string, v ...interface{}) { if l.lvl <= InfoLevel { record := NewRecord(time.Now(), fmt.Sprintf(format, v...), l.getLine(), InfoLevel) - l.output(record) + _ = l.output(record) } } @@ -220,7 +220,7 @@ func (l *Logger) Infof(format string, v ...interface{}) { func (l *Logger) Warning(v ...interface{}) { if l.lvl <= WarningLevel { record := NewRecord(time.Now(), fmt.Sprint(v...), l.getLine(), WarningLevel) - l.output(record) + _ = l.output(record) } } @@ -228,7 +228,7 @@ func (l *Logger) Warning(v ...interface{}) { func (l *Logger) Warningf(format string, v ...interface{}) { if l.lvl <= WarningLevel { record := NewRecord(time.Now(), fmt.Sprintf(format, v...), l.getLine(), WarningLevel) - l.output(record) + _ = l.output(record) } } @@ -236,7 +236,7 @@ func (l *Logger) Warningf(format string, v ...interface{}) { func (l *Logger) Error(v ...interface{}) { if l.lvl <= ErrorLevel { record := NewRecord(time.Now(), fmt.Sprint(v...), l.getLine(), ErrorLevel) - l.output(record) + _ = l.output(record) } } @@ -244,7 +244,7 @@ func (l *Logger) Error(v ...interface{}) { func (l *Logger) Errorf(format string, v ...interface{}) { if l.lvl <= ErrorLevel { record := NewRecord(time.Now(), fmt.Sprintf(format, v...), l.getLine(), ErrorLevel) - l.output(record) + _ = l.output(record) } } @@ -252,7 +252,7 @@ func (l *Logger) Errorf(format string, v ...interface{}) { func (l *Logger) Fatal(v ...interface{}) { if l.lvl <= FatalLevel { record := NewRecord(time.Now(), fmt.Sprint(v...), l.getLine(), FatalLevel) - l.output(record) + _ = l.output(record) } os.Exit(1) } @@ -261,7 +261,7 @@ func (l *Logger) Fatal(v ...interface{}) { func (l *Logger) Fatalf(format string, v ...interface{}) { if l.lvl <= FatalLevel { record := NewRecord(time.Now(), fmt.Sprintf(format, v...), l.getLine(), FatalLevel) - l.output(record) + _ = l.output(record) } os.Exit(1) } diff --git a/src/lib/orm/error.go b/src/lib/orm/error.go index 1c6fb33e8..69794630e 100644 --- a/src/lib/orm/error.go +++ b/src/lib/orm/error.go @@ -52,7 +52,7 @@ func AsNotFoundError(err error, messageFormat string, args ...interface{}) *erro if errors.Is(err, orm.ErrNoRows) { e := errors.NotFoundError(nil) if len(messageFormat) > 0 { - e.WithMessage(messageFormat, args...) + _ = e.WithMessage(messageFormat, args...) } return e } diff --git a/src/lib/request.go b/src/lib/request.go index 11cea6b82..90f9c5918 100644 --- a/src/lib/request.go +++ b/src/lib/request.go @@ -31,7 +31,7 @@ type nopCloser struct { func (n nopCloser) Read(p []byte) (int, error) { num, err := n.ReadSeeker.Read(p) if err == io.EOF { // move to start to have it ready for next read cycle - n.Seek(0, io.SeekStart) + _, _ = n.Seek(0, io.SeekStart) } return num, err } @@ -44,14 +44,14 @@ func (n nopCloser) Close() error { func copyBody(body io.ReadCloser) io.ReadCloser { // check if body was already read and converted into our nopCloser if nc, ok := body.(nopCloser); ok { - nc.Seek(0, io.SeekStart) + _, _ = nc.Seek(0, io.SeekStart) return body } defer body.Close() var buf bytes.Buffer - io.Copy(&buf, body) + _, _ = io.Copy(&buf, body) return nopCloser{bytes.NewReader(buf.Bytes())} } diff --git a/src/pkg/config/manager.go b/src/pkg/config/manager.go index 4adbc2911..ab01d6e09 100644 --- a/src/pkg/config/manager.go +++ b/src/pkg/config/manager.go @@ -48,7 +48,7 @@ func (c *CfgManager) LoadDefault() { log.Errorf("LoadDefault failed, config item, key: %v, err: %v", item.Name, err) continue } - c.Store.Set(item.Name, *cfgValue) + _ = c.Store.Set(item.Name, *cfgValue) } } } @@ -65,7 +65,7 @@ func (c *CfgManager) LoadSystemConfigFromEnv() { log.Errorf("LoadSystemConfigFromEnv failed, config item, key: %v, err: %v", item.Name, err) continue } - c.Store.Set(item.Name, *configValue) + _ = c.Store.Set(item.Name, *configValue) } } } @@ -149,7 +149,7 @@ func (c *CfgManager) Set(ctx context.Context, key string, value interface{}) { log.Errorf("error when setting key: %v, error %v", key, err) return } - c.Store.Set(key, *configValue) + _ = c.Store.Set(key, *configValue) } // GetDatabaseCfg - Get database configurations diff --git a/src/pkg/config/store/store.go b/src/pkg/config/store/store.go index 5b8340c4d..69395e7d2 100644 --- a/src/pkg/config/store/store.go +++ b/src/pkg/config/store/store.go @@ -112,7 +112,10 @@ func (c *ConfigStore) Update(ctx context.Context, cfgMap map[string]interface{}) delete(cfgMap, key) continue } - c.Set(key, *configValue) + if err := c.Set(key, *configValue); err != nil { + log.Warningf("failed to update configure item, key=%s, error: %v", key, err) + continue + } } // Update to driver return c.cfgDriver.Save(ctx, cfgMap) diff --git a/src/pkg/exporter/exporter.go b/src/pkg/exporter/exporter.go index f7d0efd93..12771d083 100644 --- a/src/pkg/exporter/exporter.go +++ b/src/pkg/exporter/exporter.go @@ -33,10 +33,13 @@ func NewExporter(opt *Opt) *Exporter { if opt.CacheDuration > 0 { CacheInit(opt) } - exporter.RegisterCollector(NewHealthCollect(hbrCli), + err := exporter.RegisterCollector(NewHealthCollect(hbrCli), NewSystemInfoCollector(hbrCli), NewProjectCollector(), NewJobServiceCollector()) + if err != nil { + log.Warningf("calling RegisterCollector() errored out, error: %v", err) + } r := prometheus.NewRegistry() r.MustRegister(exporter) @@ -69,7 +72,7 @@ func newServer(opt *Opt, r *prometheus.Registry) *http.Server { exporterMux := http.NewServeMux() exporterMux.Handle(opt.MetricsPath, promhttp.Handler()) exporterMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(` + _, _ = w.Write([]byte(`