Fail vs. fatal on store startup (#24170)
If the store fails to initialize (e.g. run a migration), it would `log.Fatal` and then `os.Exit`. Unfortunately, this trips up `TestMain`, which happily keeps running tests, now guaranteed to fail. Avoid this by instead returning an error from the store initialization, handling appropriately at the layer above.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c030bb44f5
Коммит
e39b485c4b
@@ -113,7 +113,10 @@ func initDbCmdF(command *cobra.Command, _ []string) error {
|
||||
}
|
||||
defer configStore.Close()
|
||||
|
||||
sqlStore := sqlstore.New(configStore.Get().SqlSettings, nil)
|
||||
sqlStore, err := sqlstore.New(configStore.Get().SqlSettings, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize store")
|
||||
}
|
||||
defer sqlStore.Close()
|
||||
|
||||
CommandPrettyPrintln("Database store correctly initialised")
|
||||
|
||||
@@ -64,5 +64,5 @@ func initStoreCommandContextCobra(command *cobra.Command) (store.Store, error) {
|
||||
}
|
||||
|
||||
config := cfgStore.Get()
|
||||
return sqlstore.New(config.SqlSettings, nil), nil
|
||||
return sqlstore.New(config.SqlSettings, nil)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user