mirror of https://github.com/grafana/grafana.git
Simplify error returns (gosimple)
This fixes:
pkg/api/avatar/avatar.go:261:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/log/file.go:102:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/metrics/graphitebridge/graphite.go:298:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/provisioning/provisioning.go:23:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/alert_notification.go:27:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/alert_notification.go:27:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/annotation.go:105:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/annotation.go:105:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/dashboard.go:351:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/dashboard.go:435:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/dashboard_acl.go:38:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/dashboard_acl.go:38:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/stats.go:22:2: 'if err != nil { return err }; return err' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/team.go:213:2: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/user.go:256:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/user.go:256:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/user.go:274:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/user.go:274:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/user.go:482:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
pkg/services/sqlstore/user.go:482:3: 'if err != nil { return err }; return nil' can be simplified to 'return err' (S1013)
This commit is contained in:
parent
c5a09a3dc1
commit
be2d635078
|
|
@ -258,9 +258,6 @@ func (this *thunderTask) fetch() error {
|
||||||
this.Avatar.data = &bytes.Buffer{}
|
this.Avatar.data = &bytes.Buffer{}
|
||||||
writer := bufio.NewWriter(this.Avatar.data)
|
writer := bufio.NewWriter(this.Avatar.data)
|
||||||
|
|
||||||
if _, err = io.Copy(writer, resp.Body); err != nil {
|
_, err = io.Copy(writer, resp.Body)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,7 @@ func (w *FileLogWriter) StartLogger() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.mw.SetFd(fd)
|
w.mw.SetFd(fd)
|
||||||
if err = w.initFd(); err != nil {
|
return w.initFd()
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *FileLogWriter) docheck(size int) {
|
func (w *FileLogWriter) docheck(size int) {
|
||||||
|
|
|
||||||
|
|
@ -295,11 +295,7 @@ func writeMetric(buf *bufio.Writer, m model.Metric, mf *dto.MetricFamily) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = addExtentionConventionForRollups(buf, mf, m); err != nil {
|
return addExtentionConventionForRollups(buf, mf, m)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addExtentionConventionForRollups(buf *bufio.Writer, mf *dto.MetricFamily, m model.Metric) error {
|
func addExtentionConventionForRollups(buf *bufio.Writer, mf *dto.MetricFamily, m model.Metric) error {
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,9 @@ func Init(ctx context.Context, homePath string, cfg *ini.File) error {
|
||||||
|
|
||||||
dashboardPath := path.Join(provisioningPath, "dashboards")
|
dashboardPath := path.Join(provisioningPath, "dashboards")
|
||||||
_, err := dashboards.Provision(ctx, dashboardPath)
|
_, err := dashboards.Provision(ctx, dashboardPath)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeAbsolute(path string, root string) string {
|
func makeAbsolute(path string, root string) string {
|
||||||
if filepath.IsAbs(path) {
|
if filepath.IsAbs(path) {
|
||||||
return path
|
return path
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,7 @@ func DeleteAlertNotification(cmd *m.DeleteAlertNotificationCommand) error {
|
||||||
return inTransaction(func(sess *DBSession) error {
|
return inTransaction(func(sess *DBSession) error {
|
||||||
sql := "DELETE FROM alert_notification WHERE alert_notification.org_id = ? AND alert_notification.id = ?"
|
sql := "DELETE FROM alert_notification WHERE alert_notification.org_id = ? AND alert_notification.id = ?"
|
||||||
_, err := sess.Exec(sql, cmd.OrgId, cmd.Id)
|
_, err := sess.Exec(sql, cmd.OrgId, cmd.Id)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,8 @@ func (r *SqlAnnotationRepo) Update(item *annotations.Item) error {
|
||||||
|
|
||||||
existing.Tags = item.Tags
|
existing.Tags = item.Tags
|
||||||
|
|
||||||
if _, err := sess.Table("annotation").Id(existing.Id).Cols("epoch", "text", "region_id", "tags").Update(existing); err != nil {
|
_, err = sess.Table("annotation").Id(existing.Id).Cols("epoch", "text", "region_id", "tags").Update(existing)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -347,14 +347,9 @@ func GetDashboards(query *m.GetDashboardsQuery) error {
|
||||||
|
|
||||||
err := x.In("id", query.DashboardIds).Find(&dashboards)
|
err := x.In("id", query.DashboardIds).Find(&dashboards)
|
||||||
query.Result = dashboards
|
query.Result = dashboards
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDashboardPermissionsForUser returns the maximum permission the specified user has for a dashboard(s)
|
// GetDashboardPermissionsForUser returns the maximum permission the specified user has for a dashboard(s)
|
||||||
// The function takes in a list of dashboard ids and the user id and role
|
// The function takes in a list of dashboard ids and the user id and role
|
||||||
func GetDashboardPermissionsForUser(query *m.GetDashboardPermissionsForUserQuery) error {
|
func GetDashboardPermissionsForUser(query *m.GetDashboardPermissionsForUserQuery) error {
|
||||||
|
|
@ -431,14 +426,9 @@ func GetDashboardsByPluginId(query *m.GetDashboardsByPluginIdQuery) error {
|
||||||
|
|
||||||
err := x.Where(whereExpr, query.OrgId, query.PluginId).Find(&dashboards)
|
err := x.Where(whereExpr, query.OrgId, query.PluginId).Find(&dashboards)
|
||||||
query.Result = dashboards
|
query.Result = dashboards
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type DashboardSlugDTO struct {
|
type DashboardSlugDTO struct {
|
||||||
Slug string
|
Slug string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,8 @@ func UpdateDashboardAcl(cmd *m.UpdateDashboardAclCommand) error {
|
||||||
|
|
||||||
// Update dashboard HasAcl flag
|
// Update dashboard HasAcl flag
|
||||||
dashboard := m.Dashboard{HasAcl: true}
|
dashboard := m.Dashboard{HasAcl: true}
|
||||||
if _, err := sess.Cols("has_acl").Where("id=?", cmd.DashboardId).Update(&dashboard); err != nil {
|
_, err = sess.Cols("has_acl").Where("id=?", cmd.DashboardId).Update(&dashboard)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,6 @@ func GetDataSourceStats(query *m.GetDataSourceStatsQuery) error {
|
||||||
var rawSql = `SELECT COUNT(*) as count, type FROM data_source GROUP BY type`
|
var rawSql = `SELECT COUNT(*) as count, type FROM data_source GROUP BY type`
|
||||||
query.Result = make([]*m.DataSourceStats, 0)
|
query.Result = make([]*m.DataSourceStats, 0)
|
||||||
err := x.SQL(rawSql).Find(&query.Result)
|
err := x.SQL(rawSql).Find(&query.Result)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,13 +210,9 @@ func GetTeamsByUser(query *m.GetTeamsByUserQuery) error {
|
||||||
sess.Where("team.org_id=? and team_member.user_id=?", query.OrgId, query.UserId)
|
sess.Where("team.org_id=? and team_member.user_id=?", query.OrgId, query.UserId)
|
||||||
|
|
||||||
err := sess.Find(&query.Result)
|
err := sess.Find(&query.Result)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddTeamMember adds a user to a team
|
// AddTeamMember adds a user to a team
|
||||||
func AddTeamMember(cmd *m.AddTeamMemberCommand) error {
|
func AddTeamMember(cmd *m.AddTeamMemberCommand) error {
|
||||||
return inTransaction(func(sess *DBSession) error {
|
return inTransaction(func(sess *DBSession) error {
|
||||||
|
|
|
||||||
|
|
@ -253,11 +253,8 @@ func ChangeUserPassword(cmd *m.ChangeUserPasswordCommand) error {
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Id(cmd.UserId).Update(&user); err != nil {
|
_, err := sess.Id(cmd.UserId).Update(&user)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,11 +268,8 @@ func UpdateUserLastSeenAt(cmd *m.UpdateUserLastSeenAtCommand) error {
|
||||||
LastSeenAt: time.Now(),
|
LastSeenAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Id(cmd.UserId).Update(&user); err != nil {
|
_, err := sess.Id(cmd.UserId).Update(&user)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,10 +473,7 @@ func SetUserHelpFlag(cmd *m.SetUserHelpFlagCommand) error {
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Id(cmd.UserId).Cols("help_flags1").Update(&user); err != nil {
|
_, err := sess.Id(cmd.UserId).Cols("help_flags1").Update(&user)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -566,13 +566,9 @@ func getAllMetrics(cwData *DatasourceInfo) (cloudwatch.ListMetricsOutput, error)
|
||||||
}
|
}
|
||||||
return !lastPage
|
return !lastPage
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var metricsCacheLock sync.Mutex
|
var metricsCacheLock sync.Mutex
|
||||||
|
|
||||||
func getMetricsForCustomMetrics(dsInfo *DatasourceInfo, getAllMetrics func(*DatasourceInfo) (cloudwatch.ListMetricsOutput, error)) ([]string, error) {
|
func getMetricsForCustomMetrics(dsInfo *DatasourceInfo, getAllMetrics func(*DatasourceInfo) (cloudwatch.ListMetricsOutput, error)) ([]string, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue