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

Fix other Go Report Card warnings #423

Merged
merged 7 commits into from
Mar 12, 2019
Merged

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Mar 12, 2019

Fix other warnings that we might run into on Go Report Card.

  • go vet: fix warnings about unkeyed field initialization

Add field names to struct initializers, mostly these are our private key structs.

  • go ineffassign: fix ineffective assignments

This is a neat tool that mostly catches unhandled errors (assignments to err variables that are never read). Add appropriate error handling to deal with these warnings. Pay attention to the subtle difference between = and := assignments.

  • go cyclo: reduce cyclomatic complexity

Some functions already had it too high, some got it too high after additional error handling. We can't do anything about it other than split the big functions into smaller ones and introduce helpers to avoid too many conditionals in a single function.

  • go misspell: fix a couple of typos
  • go fmt: reformat the code

Add field names to struct initializers, mostly these are our private key
structs.
This is a neat tool that mostly catches unhandled errors (assignments
to err variables that are never read). Add appropriate error handling
to deal with these warnings. Pay attention to the subtle difference
between = and := assignments.
Some functions already had it too high, some got it too high after
additional error handling. We can't do anything about it other than
split the big functions into smaller ones and introduce helpers to
avoid too many conditionals in a single function.
@ilammy ilammy added the W-GoThemis 🐹 Wrapper: GoThemis, Go API label Mar 12, 2019

clientSession, endpoint := createSecureSession(inputBuffer)
if clientSession == nil {
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we should add os.Exit(1) and some message that will explain why nothing was done?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We print an error message earlier, before returning nil here. I guess it will be enough to just exit with non-zero exit code to communicate a failure to the user: they will see the message and their terminal is likely to display a failure.

I'll add proper exit code here and in the Secure Message server example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Lagovas done.

I've improved error forwarding a bit, moved the error message printing to main() and added exiting with non-zero status code. I've also done the same to Secure Message example for the sake of consistency.

@@ -149,30 +149,34 @@ func New(key []byte, mode int) *SecureCell {
return &SecureCell{key, mode}
}

func missing(data []byte) bool {
return data == nil || len(data) == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

cool

- Split the code in Secure Message example in the same way we do
  for Secure Session.

- Improve the quit message a but. Without quotes it's not intuitive
  that you have to literally type in q-u-i-t to quit cleanly.

- Unify error reporting in the code and output messages to stderr.

- Exit with non-zero status code to indicate failure.
fmt.Println("Type your settings from https://themis.cossacklabs.com/interactive-simulator/setup/")

fmt.Println("JSON endpoint: ")
endpoint, err := inputBuffer.ReadString('\n')
if err != nil {
fmt.Println("Failed to read endpoint URL:", err)
return nil, ""
err = fmt.Errorf("Failed to read endpoint URL:", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you use fmt.Errorf and don't use any pattern for formatting: https://play.golang.org/p/3z5WE3eymGs . Use URL: %s', err)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have to agree, it's pretty dumb of me to introduce new go vet warnings after getting rid of them :) Nice catch, thank you.

Make sure that errors are printed out nicely. Ironically, previous
format strings introduced _new_ govet errors which we recently got
rid of :)
@ilammy ilammy merged commit c072a00 into cossacklabs:master Mar 12, 2019
@ilammy ilammy deleted the fix-go-report branch March 12, 2019 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
W-GoThemis 🐹 Wrapper: GoThemis, Go API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants