Commit b279d4b3 authored by Cristian Maglie's avatar Cristian Maglie

Fixed 'feedback' package initialization order

parent 9585728e
......@@ -203,19 +203,22 @@ func toLogLevel(s string) (t logrus.Level, found bool) {
}
func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat string, noColor bool, settings *rpc.Configuration) {
// initialize inventory
err := inventory.Init(settings.GetDirectories().GetData())
if err != nil {
feedback.Fatal(fmt.Sprintf("Error: %v", err), feedback.ErrInitializingInventory)
}
// https://no-color.org/
color.NoColor = noColor || os.Getenv("NO_COLOR") != ""
//
// Prepare the Feedback system
//
// Set default feedback output to colorable
color.NoColor = noColor || os.Getenv("NO_COLOR") != "" // https://no-color.org/
feedback.SetOut(colorable.NewColorableStdout())
feedback.SetErr(colorable.NewColorableStderr())
// use the output format to configure the Feedback
format, ok := feedback.ParseOutputFormat(outputFormat)
if !ok {
feedback.Fatal(tr("Invalid output format: %s", outputFormat), feedback.ErrBadArgument)
}
feedback.SetFormat(format)
//
// Prepare logging
//
......@@ -260,20 +263,14 @@ func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat stri
logrus.SetLevel(logrusLevel)
}
//
// Prepare the Feedback system
//
// use the output format to configure the Feedback
format, ok := feedback.ParseOutputFormat(outputFormat)
if !ok {
feedback.Fatal(tr("Invalid output format: %s", outputFormat), feedback.ErrBadArgument)
}
feedback.SetFormat(format)
// Print some status info and check command is consistent
logrus.Info(versioninfo.VersionInfo.Application + " version " + versioninfo.VersionInfo.VersionString)
//
// Print some status info and check command is consistent
// Initialize inventory
//
logrus.Info(versioninfo.VersionInfo.Application + " version " + versioninfo.VersionInfo.VersionString)
err := inventory.Init(settings.GetDirectories().GetData())
if err != nil {
feedback.Fatal(fmt.Sprintf("Error: %v", err), feedback.ErrInitializingInventory)
}
}
......@@ -651,7 +651,7 @@ func TestCLIStartupWithCorruptedInventory(t *testing.T) {
require.NoError(t, f.Close())
// the CLI should not be able to load inventory and report it to the logs
_, stderr, err := cli.Run("core", "update-index", "-v")
stdout, _, err := cli.Run("core", "update-index", "-v")
require.NoError(t, err)
require.Contains(t, string(stderr), "Error loading inventory store")
require.Contains(t, string(stdout), "Error loading inventory store")
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment