pkg/util: Check errors (#19832)

* pkg/util: Check errors
* pkg/services: DRY up code
This commit is contained in:
Arve Knudsen
2019-10-23 10:40:12 +02:00
committed by GitHub
parent 31a346fcf2
commit 35e0e078b7
30 changed files with 247 additions and 84 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util/errutil"
)
const AdminUserId = 1
@@ -28,7 +29,10 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SqlStore) erro
return fmt.Errorf("Could not read user from database. Error: %v", err)
}
passwordHashed := util.EncodePassword(newPassword, userQuery.Result.Salt)
passwordHashed, err := util.EncodePassword(newPassword, userQuery.Result.Salt)
if err != nil {
return err
}
cmd := models.ChangeUserPasswordCommand{
UserId: AdminUserId,
@@ -36,7 +40,7 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SqlStore) erro
}
if err := bus.Dispatch(&cmd); err != nil {
return fmt.Errorf("Failed to update user password")
return errutil.Wrapf(err, "Failed to update user password")
}
logger.Infof("\n")