Skip to content

Commit

Permalink
Do not report config initialization input errors to rollbar.
Browse files Browse the repository at this point in the history
Also, the default logger should not log verbosely by default. This cleans up error output.
  • Loading branch information
mitchell-as committed Oct 28, 2024
1 parent 20f29c8 commit bcb3421
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions cmd/state/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ func main() {
var err error
cfg, err = config.New()
if err != nil {
multilog.Critical("Could not initialize config: %v", errs.JoinMessage(err))
fmt.Fprintf(os.Stderr, "Could not load config, if this problem persists please reinstall the State Tool. Error: %s\n", errs.JoinMessage(err))
if !locale.IsInputError(err) {
multilog.Critical("Could not initialize config: %v", errs.JoinMessage(err))
fmt.Fprintf(os.Stderr, "Could not load config, if this problem persists please reinstall the State Tool. Error: %s\n", errs.JoinMessage(err))
} else {
for _, err2 := range locale.UnpackError(err) {
fmt.Fprintf(os.Stderr, err2.Error())
}
}
exitCode = 1
return
}
Expand Down
7 changes: 6 additions & 1 deletion internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ type LoggingHandler interface {

type standardHandler struct {
formatter Formatter
verbose bool
}

func (l *standardHandler) SetFormatter(f Formatter) {
l.formatter = f
}

func (l *standardHandler) SetVerbose(v bool) {
l.verbose = v
}

func (l *standardHandler) Output() io.Writer {
Expand All @@ -143,7 +145,9 @@ func (l *standardHandler) Output() io.Writer {

// default handling interface - just
func (l *standardHandler) Emit(ctx *MessageContext, message string, args ...interface{}) error {
fmt.Fprintln(os.Stderr, l.formatter.Format(ctx, message, args...))
if l.verbose {
fmt.Fprintln(os.Stderr, l.formatter.Format(ctx, message, args...))
}
return nil
}

Expand All @@ -158,6 +162,7 @@ func (l *standardHandler) Close() {}

var currentHandler LoggingHandler = &standardHandler{
DefaultFormatter,
os.Getenv("VERBOSE") != "",
}

// Set the current handler of the library. We currently support one handler, but it might be nice to have more
Expand Down
2 changes: 1 addition & 1 deletion internal/osutils/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (e *HomeDirNotFoundError) Error() string {
return homeDirNotFoundErrorMessage
}

func (e *HomeDirNotFoundError) LocalizedError() string {
func (e *HomeDirNotFoundError) LocaleError() string {
return homeDirNotFoundErrorMessage
}

Expand Down

0 comments on commit bcb3421

Please sign in to comment.