Skip to content

Commit

Permalink
fix(tmux): Handle another error we might get when listing sessions.
Browse files Browse the repository at this point in the history
I was already handling one situation where the server isn't running, but
this situation is if the tmux socket doesn't yet exist.
  • Loading branch information
JeffFaer committed Feb 19, 2024
1 parent 411a078 commit 72f0f77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions git/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (repo *gitRepo) parseOriginURL() string {
if strings.Contains(stderr, "No such remote") {
return ""
}
fmt.Fprint(os.Stderr, stderr)
fmt.Fprintln(os.Stderr, stderr)
return ""
}
for _, regex := range urlRegexes {
Expand Down Expand Up @@ -184,7 +184,7 @@ func (repo *gitRepo) configValue(key string) (string, error) {
if stderr == "" {
return "", nil
}
fmt.Fprint(os.Stderr, stderr)
fmt.Fprintln(os.Stderr, stderr)
return "", err
}
return stdout, nil
Expand Down
2 changes: 1 addition & 1 deletion git/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (cmd repoCommand) Run(repo *gitRepo) error {
orig := repoCmd.Stderr
stderr, _ := repoCmd.RunStderr()
if !strings.Contains(stderr, cmd.errorMessage) {
fmt.Fprint(orig, stderr)
fmt.Fprintln(orig, stderr)
return fmt.Errorf("did not observe expected error message containing %q", cmd.errorMessage)
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions tmux/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ func (srv *Server) Equal(other *Server) bool {
func (srv *Server) ListSessions() ([]*Session, error) {
stdout, stderr, err := srv.command("list-sessions", "-F", string(SessionID)).RunOutput()
if err != nil {
if strings.Contains(stderr, "no server running") {
if
// Socket doesn't yet exists.
strings.Contains(stderr, "No such file or directory") ||
// Socket exists, but no server owns it.
strings.Contains(stderr, "no server running") {
return nil, nil
}
fmt.Fprint(os.Stderr, stderr)
fmt.Fprintln(os.Stderr, stderr)
return nil, err
}
var res []*Session
Expand Down

0 comments on commit 72f0f77

Please sign in to comment.