Skip to content

Commit

Permalink
Merge pull request #265 from atsign-foundation/fix-error-messages
Browse files Browse the repository at this point in the history
fix: dependency upgrades + cleanup error messages in sshnp
  • Loading branch information
XavierChanth committed Jul 20, 2023
2 parents f7cf715 + b2b60f7 commit 4b25515
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
13 changes: 10 additions & 3 deletions packages/sshnoports/bin/sshnp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import 'package:at_utils/at_logger.dart';
// local packages
import 'package:sshnoports/sshnp/sshnp.dart';
import 'package:sshnoports/sshnp/cleanup.dart';
import 'package:sshnoports/sshnp/sshnp_params.dart';

void main(List<String> args) async {
AtSignLogger.root_level = 'SHOUT';
SSHNP? sshnp;

var params = SSHNPParams.fromPartial(SSHNPPartialParams.fromArgs(args));

try {
sshnp = await SSHNP.fromCommandLineArgs(args);
sshnp = await SSHNP.fromParams(params);

ProcessSignal.sigint.watch().listen((signal) async {
await cleanUp(sshnp!.sessionId, sshnp.logger);
Expand All @@ -25,8 +29,11 @@ void main(List<String> args) async {
} on ArgumentError catch (_) {
exit(1);
} catch (error, stackTrace) {
stderr.writeln('Error: ${error.toString()}');
stderr.writeln('Stack Trace: ${stackTrace.toString()}');
stderr.writeln(error.toString());

if (params.verbose) {
stderr.writeln('\nStack Trace: ${stackTrace.toString()}');
}

if (sshnp != null) {
await cleanUp(sshnp.sessionId, sshnp.logger);
Expand Down
7 changes: 5 additions & 2 deletions packages/sshnoports/lib/sshnp/sshnp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:at_client/at_client.dart';
import 'package:at_utils/at_logger.dart';
import 'package:meta/meta.dart';
import 'package:sshnoports/sshnp/sshnp_impl.dart';
import 'package:sshnoports/sshnp/sshnp_params.dart';

abstract class SSHNP {
abstract final AtSignLogger logger;
Expand Down Expand Up @@ -113,8 +114,6 @@ abstract class SSHNP {
@visibleForTesting
bool initialized = false;



factory SSHNP({
// final fields
required AtClient atClient,
Expand Down Expand Up @@ -155,6 +154,10 @@ abstract class SSHNP {
return SSHNPImpl.fromCommandLineArgs(args);
}

static Future<SSHNP> fromParams(SSHNPParams p) {
return SSHNPImpl.fromParams(p);
}

/// Must be run after construction, to complete initialization
/// - Starts notification subscription to listen for responses from sshnpd
/// - calls [generateSshKeys] which generates the ssh keypair to use
Expand Down
11 changes: 6 additions & 5 deletions packages/sshnoports/lib/sshnp/sshnp_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,13 @@ class SSHNPImpl implements SSHNP {
}
}

static Future<SSHNP> fromCommandLineArgs(List<String> args) async {
try {
var p = SSHNPParams.fromPartial(
SSHNPPartialParams.fromArgs(args),
);
static Future<SSHNP> fromCommandLineArgs(List<String> args) {
var params = SSHNPParams.fromPartial(SSHNPPartialParams.fromArgs(args));
return fromParams(params);
}

static Future<SSHNP> fromParams(SSHNPParams p) async {
try {
if (p.clientAtSign == null) {
throw ArgumentError('Option from is mandatory.');
}
Expand Down
11 changes: 5 additions & 6 deletions packages/sshnoports/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ version: 3.4.0
homepage: https://docs.atsign.com/

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.0.0 <4.0.0"


dependencies:
dependencies:
args: 2.4.2
at_client: 3.0.61
at_lookup: 3.0.37
at_client: 3.0.63
at_lookup: 3.0.38
at_onboarding_cli: 1.3.0
at_utils: 3.0.13
at_utils: 3.0.15
crypton: 2.1.0
dartssh2: 2.8.2
ssh_key: ">=0.7.1 <0.9.0"
Expand Down

0 comments on commit 4b25515

Please sign in to comment.