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

chore: Better error messages #260

Merged
merged 3 commits into from
Jul 19, 2023
Merged

chore: Better error messages #260

merged 3 commits into from
Jul 19, 2023

Conversation

XavierChanth
Copy link
Member

@XavierChanth XavierChanth commented Jul 19, 2023

- What I did

Due to some changes in the way arg parsing is done, the error messages for a bad parse is unpleasant, especially if you just want to see usage (this is what you get if you type sshnp, yuck):

Version : 3.4.0
-k, --key-file             Sending atSign's atKeys file if not in ~/.atsign/keys/
-f, --from (mandatory)     Sending (a.k.a. client) atSign
-t, --to (mandatory)       Receiving device atSign
-d, --device               Receiving device name
                           (defaults to "default")
-h, --host (mandatory)     atSign of sshrvd daemon or FQDN/IP address to connect back to
-p, --port                 TCP port to connect back to (only required if --host specified a FQDN/IP)
                           (defaults to "22")
-l, --local-port           Reverse ssh port to listen on, on your local machine, by sshnp default finds a spare port
                           (defaults to "0")
-s, --ssh-public-key       Public key file from ~/.ssh to be appended to authorized_hosts on the remote device
                           (defaults to "false")
-o, --local-ssh-options    Add these commands to the local ssh command
-v, --[no-]verbose         More logging
-r, --[no-]rsa             Use RSA 4096 keys rather than the default ED25519 keys
-u, --remote-user-name     username to use in the ssh session on the remote host
    --config-file          Read args from a config file
                           Mandatory args are not required if already supplied in the config file
Null check operator used on a null value
Unhandled exception:
Null check operator used on a null value
#0      new SSHNPParams.fromPartial (package:sshnoports/sshnp/sshnp_params.dart:53)
#1      SSHNPImpl.fromCommandLineArgs (package:sshnoports/sshnp/sshnp_impl.dart:189)
#2      SSHNP.fromCommandLineArgs (package:sshnoports/sshnp/sshnp.dart:149)
#3      main (file:///Users/chant/src/af/sshnoports/packages/sshnoports/bin/sshnp.dart:14)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:294)
#5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189)

Change: Moved creation of SSHNP / SSHNPD/ SSHRVD class into the try block, and added a separate on catch:

} on ArgumentError catch (_) {
    exit(1);
  }

Net change is cleaner, easier to read ArgumentError messages when printing usage:

Version : 3.4.0
-k, --key-file             Sending atSign's atKeys file if not in ~/.atsign/keys/
-f, --from (mandatory)     Sending (a.k.a. client) atSign
-t, --to (mandatory)       Receiving device atSign
-d, --device               Receiving device name
                           (defaults to "default")
-h, --host (mandatory)     atSign of sshrvd daemon or FQDN/IP address to connect back to
-p, --port                 TCP port to connect back to (only required if --host specified a FQDN/IP)
                           (defaults to "22")
-l, --local-port           Reverse ssh port to listen on, on your local machine, by sshnp default finds a spare port
                           (defaults to "0")
-s, --ssh-public-key       Public key file from ~/.ssh to be appended to authorized_hosts on the remote device
                           (defaults to "false")
-o, --local-ssh-options    Add these commands to the local ssh command
-v, --[no-]verbose         More logging
-r, --[no-]rsa             Use RSA 4096 keys rather than the default ED25519 keys
-u, --remote-user-name     username to use in the ssh session on the remote host
    --config-file          Read args from a config file
                           Mandatory args are not required if already supplied in the config file

Invalid argument(s): Option from is mandatory.

- How I did it

- How to verify it

- Description for the changelog
chore: Better error messages

@XavierChanth XavierChanth merged commit 94a3a71 into trunk Jul 19, 2023
@XavierChanth XavierChanth deleted the error-messages branch July 21, 2023 18:17
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.

2 participants