Skip to content

Commit acb622c

Browse files
committed
Fixed 'feedback' package initialization order
1 parent 90b805d commit acb622c

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

internal/cli/cli.go

+18-21
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,22 @@ func toLogLevel(s string) (t logrus.Level, found bool) {
203203
}
204204

205205
func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat string, noColor bool, settings *rpc.Configuration) {
206-
// initialize inventory
207-
err := inventory.Init(settings.GetDirectories().GetData())
208-
if err != nil {
209-
feedback.Fatal(fmt.Sprintf("Error: %v", err), feedback.ErrInitializingInventory)
210-
}
211-
212-
// https://no-color.org/
213-
color.NoColor = noColor || os.Getenv("NO_COLOR") != ""
206+
//
207+
// Prepare the Feedback system
208+
//
214209

215210
// Set default feedback output to colorable
211+
color.NoColor = noColor || os.Getenv("NO_COLOR") != "" // https://no-color.org/
216212
feedback.SetOut(colorable.NewColorableStdout())
217213
feedback.SetErr(colorable.NewColorableStderr())
218214

215+
// use the output format to configure the Feedback
216+
format, ok := feedback.ParseOutputFormat(outputFormat)
217+
if !ok {
218+
feedback.Fatal(tr("Invalid output format: %s", outputFormat), feedback.ErrBadArgument)
219+
}
220+
feedback.SetFormat(format)
221+
219222
//
220223
// Prepare logging
221224
//
@@ -260,20 +263,14 @@ func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat stri
260263
logrus.SetLevel(logrusLevel)
261264
}
262265

263-
//
264-
// Prepare the Feedback system
265-
//
266-
267-
// use the output format to configure the Feedback
268-
format, ok := feedback.ParseOutputFormat(outputFormat)
269-
if !ok {
270-
feedback.Fatal(tr("Invalid output format: %s", outputFormat), feedback.ErrBadArgument)
271-
}
272-
feedback.SetFormat(format)
266+
// Print some status info and check command is consistent
267+
logrus.Info(versioninfo.VersionInfo.Application + " version " + versioninfo.VersionInfo.VersionString)
273268

274269
//
275-
// Print some status info and check command is consistent
270+
// Initialize inventory
276271
//
277-
278-
logrus.Info(versioninfo.VersionInfo.Application + " version " + versioninfo.VersionInfo.VersionString)
272+
err := inventory.Init(settings.GetDirectories().GetData())
273+
if err != nil {
274+
feedback.Fatal(fmt.Sprintf("Error: %v", err), feedback.ErrInitializingInventory)
275+
}
279276
}

internal/integrationtest/board/board_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ func TestCLIStartupWithCorruptedInventory(t *testing.T) {
651651
require.NoError(t, f.Close())
652652

653653
// the CLI should not be able to load inventory and report it to the logs
654-
_, stderr, err := cli.Run("core", "update-index", "-v")
654+
stdout, _, err := cli.Run("core", "update-index", "-v")
655655
require.NoError(t, err)
656-
require.Contains(t, string(stderr), "Error loading inventory store")
656+
require.Contains(t, string(stdout), "Error loading inventory store")
657657
}

0 commit comments

Comments
 (0)