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

[test-port-forwarding.pl] fix: add human-readable error when nc is not installed on the host #2764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mr-Sunglasses
Copy link

fix: #2707

Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

I don't really care either way about the here-document, but the repeated test for -f $instance should be eliminated.

my $instance = shift;

# Check for netcat before proceeding
check_netcat_installed() unless -f $instance;
Copy link
Member

Choose a reason for hiding this comment

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

Why not move the check after the if (-f $instance) block below, so you don't need to repeat the check?

And given that the whole file is just one long script, I think the code should just be inlined and not put into a function.

Comment on lines +28 to +32
die "Error: 'nc' (netcat) is not installed on the host system.\n" .
"Please install netcat to run this test script:\n" .
" - On macOS: brew install netcat\n" .
" - On Ubuntu/Debian: sudo apt-get install netcat\n" .
" - On RHEL/CentOS: sudo yum install nmap-ncat\n";
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't really matter, but instead of all the explicit newlines and concatenation you could use a here-document:

Suggested change
die "Error: 'nc' (netcat) is not installed on the host system.\n" .
"Please install netcat to run this test script:\n" .
" - On macOS: brew install netcat\n" .
" - On Ubuntu/Debian: sudo apt-get install netcat\n" .
" - On RHEL/CentOS: sudo yum install nmap-ncat\n";
die <<"end_of_message";
Error: 'nc' (netcat) is not installed on the host system.
Please install netcat to run this test script:
- On macOS: brew install netcat
- On Ubuntu/Debian: sudo apt-get install netcat
- On RHEL/CentOS: sudo yum install nmap-ncat
end_of_message

@@ -20,8 +20,24 @@
use Socket qw(inet_ntoa);
use Sys::Hostname qw(hostname);

# check for nc
sub check_netcat_installed {
my $nc_path = `which nc 2>/dev/null`;
Copy link
Member

Choose a reason for hiding this comment

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

which is often missing. command -v should work.

@AkihiroSuda AkihiroSuda changed the title fix: add human-readable error when nc is not installed on the host [test-port-forwarding.pl] fix: add human-readable error when nc is not installed on the host Oct 19, 2024
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.

hack/test-port-forwarding.pl should print a human-readable error when nc is not installed on the host
3 participants