mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 21:42:38 +08:00
pkg/cmd: Check errors (#19700)
* pkg/cmd: Check errors * pkg/cmd: Make sure server waits on services, even in case of error * pkg/cmd: Inform of error to show help * pkg/cmd: Only warn on failure to send systemd notification * pkg/cmd: Don't log errors stemming from context cancelation * pkg/cmd: Don't fail if unable to write to systemd
This commit is contained in:
@ -22,11 +22,14 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore *sqlstore
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
configOptions := strings.Split(cmd.GlobalString("configOverrides"), " ")
|
||||
cfg.Load(&setting.CommandLineArgs{
|
||||
if err := cfg.Load(&setting.CommandLineArgs{
|
||||
Config: cmd.ConfigFile(),
|
||||
HomePath: cmd.HomePath(),
|
||||
Args: append(configOptions, cmd.Args()...), // tailing arguments have precedence over the options string
|
||||
})
|
||||
}); err != nil {
|
||||
logger.Errorf("\n%s: Failed to load configuration", color.RedString("Error"))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if debug {
|
||||
cfg.LogConfigSources()
|
||||
@ -35,13 +38,19 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore *sqlstore
|
||||
engine := &sqlstore.SqlStore{}
|
||||
engine.Cfg = cfg
|
||||
engine.Bus = bus.GetBus()
|
||||
engine.Init()
|
||||
if err := engine.Init(); err != nil {
|
||||
logger.Errorf("\n%s: Failed to initialize SQL engine", color.RedString("Error"))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := command(cmd, engine); err != nil {
|
||||
logger.Errorf("\n%s: ", color.RedString("Error"))
|
||||
logger.Errorf("%s\n\n", err)
|
||||
|
||||
cmd.ShowHelp()
|
||||
if err := cmd.ShowHelp(); err != nil {
|
||||
logger.Errorf("\n%s: Failed to show help: %s %s\n\n", color.RedString("Error"),
|
||||
color.RedString("✗"), err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -57,7 +66,10 @@ func runPluginCommand(command func(commandLine utils.CommandLine) error) func(co
|
||||
logger.Errorf("\n%s: ", color.RedString("Error"))
|
||||
logger.Errorf("%s %s\n\n", color.RedString("✗"), err)
|
||||
|
||||
cmd.ShowHelp()
|
||||
if err := cmd.ShowHelp(); err != nil {
|
||||
logger.Errorf("\n%s: Failed to show help: %s %s\n\n", color.RedString("Error"),
|
||||
color.RedString("✗"), err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user