From 877f01a3587a84541ad39058159c4918555583e0 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sat, 26 Jan 2019 14:04:28 -0800 Subject: [PATCH] Cleaning up ineffectual error checking and misspellings --- application/examples/echobot/main.go | 7 ++++++- connection/connection.go | 6 ++++++ connection/control_channel_test.go | 8 ++++++++ connectivity/torProvider.go | 2 +- inbound_version_negotiation_test.go | 25 +++++++++++++++++++++++++ testing/quality.sh | 10 +++++++++- 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/application/examples/echobot/main.go b/application/examples/echobot/main.go index 174e249..0696638 100644 --- a/application/examples/echobot/main.go +++ b/application/examples/echobot/main.go @@ -49,7 +49,7 @@ func (ebi *EchoBotInstance) ChatMessage(messageID uint32, when time.Time, messag return true } -// ChatMessageAck is called whenever a connected peer acknolwedges a message that EchoBot sent. +// ChatMessageAck is called whenever a connected peer acknowledges a message that EchoBot sent. func (ebi *EchoBotInstance) ChatMessageAck(messageID uint32, accepted bool) { } @@ -86,6 +86,11 @@ func main() { echobot := new(application.RicochetApplication) cpubk, cprivk, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + log.Errorf("Error generating keys: %v", err) + os.Exit(1) + } + // Turn on the echobot onion service in Tor. listenService, err := acn.Listen(cprivk, application.RicochetPort) if err != nil { diff --git a/connection/connection.go b/connection/connection.go index 28208e1..347c131 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -381,6 +381,12 @@ func (rc *Connection) controlPacket(handler Handler, res *Protocol_Data_Control. return rc.channelManager.OpenChannelRequestFromPeer(opm.GetChannelIdentifier(), chandler) } channel, err := rc.buildChannel(chandler, openChannel) + + if err != nil { + log.Errorf("Failed to build channel from Control Packet: %v", err) + return + } + response, err := chandler.OpenInbound(channel, opm) _, err = rc.handleChannelOpening(channel, response, err) if err != nil { diff --git a/connection/control_channel_test.go b/connection/control_channel_test.go index 6e4787f..2edafca 100644 --- a/connection/control_channel_test.go +++ b/connection/control_channel_test.go @@ -23,6 +23,10 @@ func TestChannelResultNotOpened(t *testing.T) { chatChannel := new(channels.ChatChannel) _, err := ccm.OpenChannelRequestFromPeer(2, chatChannel) + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + cr := &Protocol_Data_Control.ChannelResult{ ChannelIdentifier: proto.Int32(2), Opened: proto.Bool(false), @@ -40,6 +44,10 @@ func TestChannelResultError(t *testing.T) { chatChannel := new(channels.ChatChannel) _, err := ccm.OpenChannelRequestFromPeer(2, chatChannel) + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + cr := &Protocol_Data_Control.ChannelResult{ ChannelIdentifier: proto.Int32(3), Opened: proto.Bool(false), diff --git a/connectivity/torProvider.go b/connectivity/torProvider.go index 3f2253c..b3c072f 100644 --- a/connectivity/torProvider.go +++ b/connectivity/torProvider.go @@ -310,7 +310,7 @@ func checkCmdlineTorVersion(torCmd string) bool { } // returns true if supplied version meets our min requirments -// min requirment 0.3.5.x +// min requirement: 0.3.5.x func minTorVersionReqs(torversion string) bool { torversions := strings.Split(torversion, ".") //eg: 0.3.4.8 or 0.3.5.1-alpha log.Debugf("torversions: %v", torversions) diff --git a/inbound_version_negotiation_test.go b/inbound_version_negotiation_test.go index ef288fd..655cfb3 100644 --- a/inbound_version_negotiation_test.go +++ b/inbound_version_negotiation_test.go @@ -26,6 +26,11 @@ func TestNegotiateInboundVersions(t *testing.T) { defer l.Close() go connect() conn, err := l.Accept() + + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + _, err = NegotiateVersionInbound(conn) if err != nil { t.Errorf("Expected Success Got %v", err) @@ -52,6 +57,11 @@ func TestBadProtcolLength(t *testing.T) { defer l.Close() go connect() conn, err := l.Accept() + + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + _, err = NegotiateVersionInbound(conn) if err != io.ErrUnexpectedEOF { t.Errorf("Invalid Error Received. Expected ErrUnexpectedEOF. Got %v", err) @@ -78,6 +88,11 @@ func TestNoSupportedVersions(t *testing.T) { defer l.Close() go connect() conn, err := l.Accept() + + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + _, err = NegotiateVersionInbound(conn) if err != utils.VersionNegotiationError { t.Errorf("Invalid Error Received. Expected VersionNegotiationError. Got %v", err) @@ -104,6 +119,11 @@ func TestInvalidVersionList(t *testing.T) { defer l.Close() go connect() conn, err := l.Accept() + + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + _, err = NegotiateVersionInbound(conn) if err != utils.VersionNegotiationError { t.Errorf("Invalid Error Received. Expected VersionNegotiationError. Got %v", err) @@ -130,6 +150,11 @@ func TestNoCompatibleVersions(t *testing.T) { defer l.Close() go connect() conn, err := l.Accept() + + if err != nil { + t.Errorf("Error setting up test: %v", err) + } + _, err = NegotiateVersionInbound(conn) if err != utils.VersionNegotiationFailed { t.Errorf("Invalid Error Received. Expected VersionNegotiationFailed. Got %v", err) diff --git a/testing/quality.sh b/testing/quality.sh index fb20dfd..98fbc67 100755 --- a/testing/quality.sh +++ b/testing/quality.sh @@ -12,4 +12,12 @@ echo "" echo "Linting:" # Ignore wire packages as they are autogenerated -go list ./... | grep -v "/wire/" | xargs golint \ No newline at end of file +go list ./... | grep -v "/wire/" | xargs golint + +# ineffassign (https://github.com/gordonklaus/ineffassign) +echo "Checking for ineffectual assignment of errors (unchecked errors...)" +ineffassign . + +# misspell (https://github.com/client9/misspell) +echo "Checking for misspelled words..." +go list ./... | grep -v "/wire/" | grep -v "/vendor/" | xargs misspell \ No newline at end of file