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

Fix: Improve error handling for missing SSH client and add unit tests for shell command #200

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

asideofcode-dev
Copy link

@asideofcode-dev asideofcode-dev commented Aug 15, 2024

Summary

NOTE: The first 3 commits are based off the preceding PR #198.

Resolves #185

This PR addresses the issue where running the brev shell command in a Docker environment without an installed SSH client would cause a panic. Additionally, it improves the error handling when the specified workspace cannot be found.

Key changes

  1. SSH Client Check:

    • Added a check to ensure that the SSH client is installed and available in the system's PATH before attempting to establish a connection. If the SSH client is not found, a clear and actionable error message is returned.
  2. Unit Tests:

    • Added unit tests to verify the behavior when the SSH client is not installed, ensuring that the error is properly caught and reported.
    • Added a test case to validate that an appropriate error is raised when the workspace is not found.
  3. Code Cleanup:

    • Performed minor formatting improvements and removed unnecessary whitespace for cleaner code.

Impact

  • Users running brev shell in environments without an SSH client will now receive a clear error message guiding them to install the required software.
  • Ensures robustness in handling edge cases where the specified workspace cannot be found.

- Refactored the `ls` command to include argument routing directly within the `RunE` function for improved clarity and maintainability.
- Replaced `if-else` statements in `handleLsArg` with a cleaner `switch` statement.
- Updated the help output to properly display valid arguments for the `ls` command, enhancing user guidance.
- Improved error handling, particularly for invalid arguments and admin-only operations.
- Refactored `NewCmdLs` to include dynamic routing and improved user experience.
- Introduced new unit tests for various `ls` command scenarios, ensuring coverage for no args, valid args, invalid args, and specific flag handling.
- Added a `NewTestTerminal` function to facilitate testing by providing an easily configurable terminal instance with buffers for `stdout`, `stderr`, and verbose output.
… for `shell` command

- Added error handling for scenarios where the SSH client is not installed or not available in the PATH.
- Updated unit tests to cover SSH client availability and workspace not found errors.
- Minor code cleanup and formatting improvements in the `ls` and `shell` commands.
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.

Running brev shell in docker ubuntu causes panic if ssh-client is not installed.
1 participant