-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix(daemon): make status harmless. #2987
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,9 +306,5 @@ func GetClient(ctx context.Context, repoRoot turbopath.AbsoluteSystemPath, logge | |
LogPath: logPath, | ||
TurboVersion: turboVersion, | ||
} | ||
client, err := c.Connect(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return client, nil | ||
return c.Connect(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is 1:1. at no place can you get both a client and an error. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ package daemon | |
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/vercel/turbo/cli/internal/cmdutil" | ||
"github.com/vercel/turbo/cli/internal/daemon/connector" | ||
"github.com/vercel/turbo/cli/internal/daemonclient" | ||
|
@@ -34,6 +34,9 @@ func (l *lifecycle) status(ctx context.Context, outputJSON bool) error { | |
// If the daemon is not running, the status is that it's not running. | ||
// We don't want to start it just to check the status. | ||
DontStart: true, | ||
// If the daemon is a different version simply report that. | ||
// Don't attempt to kill the existing daemon. | ||
DontKill: true, | ||
}) | ||
if err != nil { | ||
return l.reportStatusError(err, outputJSON) | ||
|
@@ -60,22 +63,27 @@ func (l *lifecycle) status(ctx context.Context, outputJSON bool) error { | |
} | ||
|
||
func (l *lifecycle) reportStatusError(err error, outputJSON bool) error { | ||
var msg string | ||
// Determine the unwrapped error message that we want to render. | ||
var toRender error | ||
if errors.Is(err, connector.ErrDaemonNotRunning) { | ||
msg = "the daemon is not running" | ||
toRender = connector.ErrDaemonNotRunning | ||
} else if errors.Is(err, connector.ErrVersionMismatch) { | ||
toRender = connector.ErrVersionMismatch | ||
} else { | ||
msg = err.Error() | ||
toRender = err | ||
} | ||
|
||
Comment on lines
+66
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Instead of magic-stringing it like previously, we just let the error speak for itself. |
||
// Spit it out as plain text or JSON. | ||
if outputJSON { | ||
rendered, err := json.MarshalIndent(map[string]string{ | ||
"error": msg, | ||
rendered, jsonErr := json.MarshalIndent(map[string]string{ | ||
"error": toRender.Error(), | ||
}, "", " ") | ||
if err != nil { | ||
return err | ||
if jsonErr != nil { | ||
return jsonErr | ||
} | ||
l.base.UI.Output(string(rendered)) | ||
} else { | ||
l.base.UI.Output(fmt.Sprintf("Failed to contact daemon: %v", msg)) | ||
l.base.UI.Output(fmt.Sprintf("Failed to contact daemon: %v", toRender.Error())) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now shared.