Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail if an error log has occured #41

Merged
merged 4 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions cmd/klotho/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ var cfg struct {
}

var hadWarnings = atomic.NewBool(false)
var hadErrors = atomic.NewBool(false)

func init() {
err := zap.RegisterEncoder("klotho-cli", func(zcfg zapcore.EncoderConfig) (zapcore.Encoder, error) {
return logging.NewConsoleEncoder(cfg.verbose, hadWarnings), nil
return logging.NewConsoleEncoder(cfg.verbose, hadWarnings, hadErrors), nil
})

if err != nil {
Expand Down Expand Up @@ -83,11 +84,7 @@ func main() {

err := root.Execute()
if err != nil {
if cfg.internalDebug {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was confused on why we have this. just reprints errors it looks like so i removed it. If theres a reason to have it ill add it back and have to change my implementation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is in the format: %+v vs %v. The + gives a full stack trace, which is only relevant for us developers and not for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so do we want to have it as a cli flag then? because this could be exposed to the end user right?

zap.S().Errorf("%+v", err)
} else if !root.SilenceErrors {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this regress the silence errors (which we set on line 270 so it doesn't double-print)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, we still set that to make sure that we dont double print anything

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we actually will want this so that the non plugin errors surface, going to add it back

zap.S().Errorf("%v", err)
}
zap.S().Error("Klotho compilation failed")
os.Exit(1)
}
if hadWarnings.Load() && cfg.strict {
Expand Down Expand Up @@ -264,13 +261,15 @@ func run(cmd *cobra.Command, args []string) (err error) {
analyticsClient.Info("klotho compiling")

result, err := compiler.Compile(input)
if err != nil {
errHandler.PrintErr(err)
if err != nil || hadErrors.Load() {
if err != nil {
errHandler.PrintErr(err)
}
analyticsClient.Error("klotho compiling failed")

cmd.SilenceErrors = true
cmd.SilenceUsage = true
return err
return errors.New("Failed run of klotho invocation")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we always set SilenceErrors to true it shouldnt matter what we return, just that we return some error

}

if cfg.uploadSource {
Expand Down
13 changes: 9 additions & 4 deletions pkg/logging/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ type ConsoleEncoder struct {
Annotation annotationField
Node astNodeField
HadWarnings *atomic.Bool
HadErrors *atomic.Bool

*bufferEncoder
}

func NewConsoleEncoder(verbose bool, hadWarnings *atomic.Bool) *ConsoleEncoder {
func NewConsoleEncoder(verbose bool, hadWarnings *atomic.Bool, hadErrors *atomic.Bool) *ConsoleEncoder {
return &ConsoleEncoder{
Verbose: verbose,
HadWarnings: hadWarnings,
HadErrors: hadErrors,
bufferEncoder: &bufferEncoder{b: pool.Get()},
}
}
Expand All @@ -68,9 +70,9 @@ func (enc *ConsoleEncoder) Clone() zapcore.Encoder {
bufferEncoder: &bufferEncoder{b: pool.Get()},
Verbose: enc.Verbose,
HadWarnings: enc.HadWarnings,

File: enc.File,
Annotation: enc.Annotation,
HadErrors: enc.HadErrors,
File: enc.File,
Annotation: enc.Annotation,
}
_, _ = ne.bufferEncoder.b.Write(enc.b.Bytes())

Expand Down Expand Up @@ -110,6 +112,9 @@ func (enc *ConsoleEncoder) EncodeEntry(ent zapcore.Entry, fieldList []zapcore.Fi
if ent.Level >= zapcore.WarnLevel {
enc.HadWarnings.Store(true)
}
if ent.Level >= zapcore.ErrorLevel {
enc.HadErrors.Store(true)
}

var (
file = enc.File.f
Expand Down