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:
Arve Knudsen
2019-10-15 16:44:15 +02:00
committed by GitHub
parent 7da2156237
commit 573e78feeb
7 changed files with 70 additions and 34 deletions

View File

@ -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)
}