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

Improves error reporting #996

Merged
merged 2 commits into from
Aug 20, 2024
Merged

Improves error reporting #996

merged 2 commits into from
Aug 20, 2024

Conversation

DavidSeptimus-Klotho
Copy link
Contributor

@DavidSeptimus-Klotho DavidSeptimus-Klotho commented Aug 16, 2024

  • In concise mode, errors are rendered cleanly at the end of the terminal output
  • Silenced cobra error logging to avoid breaking our TUI output
  • Added error detection for language host startup
  • Added error messages to clarify issues with the klotho sdk installation

image

pkg/k2/language_host/language_host.go Outdated Show resolved Hide resolved
@@ -47,7 +47,7 @@ func (c *LogCore) With(f []zapcore.Field) zapcore.Core {
if c.verbosity.CombineLogs() {
field.AddTo(nc.enc)
}
// else (if the field is the construct and we're not combining logs) don't add it to the encoder
// else (if the field is the construct and we're not combining errors) don't add it to the encoder
Copy link
Contributor

Choose a reason for hiding this comment

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

Combing logs is the correct word here. This describes the difference, for eg, between -v=2 and -v=3

Comment on lines 30 to 31
// CombineLogs controls whether to show all errors commingled in the TUI.
// In other words, sorted by timestamp, not grouped by construct.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this comment is accurate - it's still just the logs comingled (uses program.Println) or grouped (uses tui.model).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sigh Intellij refactoring strikes again.

func NewServerState(log *zap.SugaredLogger) *ServerState {
return &ServerState{
Log: log,
Done: make(chan any),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: chan any uses the size of a pointer whereas chan struct{} uses zero size. It also uses the types to indicate that it's just a signal, and that no meaningful information other than its completion can be derived from the channel. It's not a big deal, but just explaining why it was that previously.

pkg/k2/language_host/language_host.go Show resolved Hide resolved
- In concise mode, errors are rendered cleanly at the end of the terminal output
- Silenced cobra error logging to avoid breaking our TUI output
- Added error detection for language host startup
- Added error messages to clarify issues with the klotho sdk installation
}

if f.Address != "" || f.Error != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this condition is inverted - those conditions are when it is already closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If one of those is not nil/empty, we close the channel. This is the only place we close the channel. What am I missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider the 2nd time an Error or Address are encountered, this condition would be true the second time, resulting in a double close. Unless we're doing something to shut it down, but I don't think we are (and not sure we should for cases like Address -> Error).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just updated this change. Now, we gate the close behind an if-else-if, so it only calls one or the other. Once Either branch evaluates to true, we close the channel and any subsequent calls to write will just return immediately. So you only get either an error or an address, but never both.

Once an error or address is captured, ServerState.Write() should just do nothing on subsequent writes. In conjunction with if-else-if, it ensures that we only close the Done channel once.
@DavidSeptimus-Klotho DavidSeptimus-Klotho merged commit 6d9cdf4 into main Aug 20, 2024
6 checks passed
@DavidSeptimus-Klotho DavidSeptimus-Klotho deleted the language-host-errors branch August 20, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants