-
Notifications
You must be signed in to change notification settings - Fork 109
Make Server.has_session() use returncode #68
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
Make Server.has_session() use returncode #68
Conversation
has_session() would erroneously return true if tmux returned an unexpected string, such as "no current session". Instead of adding yet another string to the list to check against, use the return code of the 'tmux has-session' command, which is documented to return 0 (Shell true) if targeted session exists, and return 1 (Shell false) in any other case.
Adresses #67 |
Codecov Report
@@ Coverage Diff @@
## master #68 +/- ##
==========================================
+ Coverage 79.97% 80.14% +0.16%
==========================================
Files 8 8
Lines 844 836 -8
==========================================
- Hits 675 670 -5
+ Misses 169 166 -3
Continue to review full report at Codecov.
|
That simplification looks nice. To play devil's advocate / pythonics: What about keep the string comparisons and raising exceptions? e.g. https://libtmux.git-pull.com/en/latest/api.html#exceptions and https://github.com/tony/libtmux/blob/189114cde7e125a482ab984749637fa44d66b284/libtmux/common.py#L523 Older versions of tmux could still subclass a new command base exception like That way the front-end user could |
I need more time on this, because I need to research and assure consistent behavior across older tmux versions. Does #67 still happen? Does it happen with all tmux versions, or only certain ones? In #67 (comment) it says:
Can you try again? Have you ruled out it being a partial/fnmatch of the session name? |
Sorry for the late response, I am having issues keeping up with the project. I'm seeking maintainers @ tmux-python/tmuxp#290. If you (or someone you know) may be interested in helping maintain libtmux or tmuxp, feel free to contact me by email or in the tmux-python/tmuxp#290 issue. |
@tony the #67 was caused by the relatively rare situation of a tmux session remaining alive with no sessions, likely due to still having an attached client (somehow) and thus causing an unexpected error message when calling This PR would fix that issue, and also provide resistance against future changes to |
@Shados thank you for the extra info! @jlargentaye Thanks for the patch! Looks good so far: https://travis-ci.org/tmux-python/libtmux/builds/352060852 If things go well, we can have this shipped out to 0.8.0, hopefully today. |
has_session() would erroneously return true if tmux returned an unexpected
string, such as "no current session".
Instead of adding yet another string to the list to check against, use the
return code of the 'tmux has-session' command, which is documented to return 0
(Shell true) if targeted session exists, and return 1 (Shell false) in any
other case.
This is untested. While it passed selftest, so did the unpatched version.