From d955ee7efe5bba090d9eba2c7c8551ed119c4e0c Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:58:27 +0530 Subject: [PATCH] ran dart analyze and fixed issues --- bin/nostr_console.dart | 1 + lib/console_ui.dart | 9 ++++++--- lib/event_ds.dart | 12 +++++++----- lib/tree_ds.dart | 9 ++++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bin/nostr_console.dart b/bin/nostr_console.dart index 63f14f3..adee597 100644 --- a/bin/nostr_console.dart +++ b/bin/nostr_console.dart @@ -90,6 +90,7 @@ Future main(List arguments) async { gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2; } on StdoutException catch (e) { print("Cannot find terminal size. Left aligning by default."); + if( gDebug > 0) log.info("${e.message}"); gNumLeftMarginSpaces = 0; } // undo above if left option is given diff --git a/lib/console_ui.dart b/lib/console_ui.dart index c06eea1..b4aa6d7 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -190,7 +190,6 @@ Future otherMenuUi(Tree node, var contactList) async { // if contact list was found, get user's feed, and keep the contact list for later use String authorName = gKindONames[pubkey.first]?.name??""; - List contactList = []; printUnderlined("\nProfile for User"); print("\nName : $authorName ( ${pubkey.first} )."); @@ -324,10 +323,12 @@ Future otherMenuUi(Tree node, var contactList) async { gNumLastDays = int.parse(newNumDays); print("Changed number of days printed to $gNumLastDays"); } on FormatException catch (e) { - print("Invalid input. Kindly try again."); + print("Invalid input. Kindly try again."); + if( gDebug > 0) print(" ${e.message}"); continue; } on Exception catch (e) { - print("Invalid input. Kindly try again."); + print("Invalid input. Kindly try again."); + if( gDebug > 0) print(" ${e}"); continue; } @@ -453,6 +454,8 @@ Future mainMenuUi(Tree node, var contactList) async { } gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2; } on StdoutException catch (e) { + print("Terminal information not available"); + if( gDebug>0) print("${e.message}"); gNumLeftMarginSpaces = 0; } } diff --git a/lib/event_ds.dart b/lib/event_ds.dart index f313024..0b62b61 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -313,7 +313,7 @@ class EventData { try { translator .translate(content, to: 'en') - .catchError( (error, stackTrace) => null ) + //.catchError( (error, stackTrace) => null ) .then( (result) => { evaluatedContent = "$evaluatedContent\n\nTranslation: ${result.toString()}" , if( gDebug > 0) print("Google translate returned successfully for one call.")} ); } on Exception catch(err) { @@ -344,9 +344,7 @@ class EventData { int n = 4; String maxN(String v) => v.length > n? v.substring(0,n) : v.substring(0, v.length); void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$colorEndMarker"):stdout.write(s); - - DateTime dTime = DateTime.fromMillisecondsSinceEpoch(createdAt *1000); - + // TODO do it in one call final df1 = DateFormat('hh:mm a'); final df2 = DateFormat(DateFormat.YEAR_ABBR_MONTH_DAY); @@ -449,6 +447,9 @@ class Event { } return Event(json[0] as String, json[1] as String, EventData.fromJson(json[2]), [relay], d ); } on Exception catch(e) { + if( gDebug> 0) { + print("Could not create event. returning dummy event. $e"); + } return Event("","",EventData("non","", 0, 0, "", [], [], [], [[]], {}), [relay], "[json]"); } } @@ -539,8 +540,9 @@ Set readEventsFromFile(String filename) { Event e = Event.fromJson(lines[i], ""); events.add(e); } - } on Exception catch(err) { + } on Exception catch(e) { print("cannot open file $gEventsFilename"); + print("Could not open file. error = $e"); } return events; diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 75bf98a..937617b 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -90,7 +90,6 @@ class Tree { rooms[chatRoomId]?.name = json['name']; } } else { - List temp = []; String roomName = "", roomAbout = ""; if( json.containsKey('name') ) { roomName = json['name']; @@ -104,7 +103,7 @@ class Tree { //if( gDebug > 0) print("Added new chat room $chatRoomId with name ${json['name']} ."); } } on Exception catch(e) { - if( gDebug > 0) print("In From Event. Event type 40. Json Decode error for event id ${value.e.eventData.id}"); + if( gDebug > 0) print("In From Event. Event type 40. Json Decode error for event id ${value.e.eventData.id}. error = $e"); } } @@ -364,7 +363,7 @@ class Tree { int numPrinted = 0; // for the top most tree, create a smaller list which only has recent trees - List latestTrees = []; // TODO + //List latestTrees = []; // TODO if( whetherTopMost) { depth = depth - 1; @@ -555,8 +554,9 @@ class Tree { } print("\n\nWrote total $eventCounter events to file \"$gEventsFilename\" of which ${countPosts + 1} are posts.") ; // TODO remove extra 1 - } on Exception catch (err) { + } on Exception catch (e) { print("Could not open file $filename."); + if( gDebug > 0) print("Could not open file: $e"); } return; @@ -899,7 +899,6 @@ class Tree { void printSocialDistance(String otherPubkey, String otherName) { String otherName = getAuthorName(otherPubkey); - List contactList = []; Event? contactEvent = this.getContactEvent(userPublicKey); bool isFollow = false; int numSecond = 0; // number of your follows who follow the other