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 --output-document flag #8121

Closed
wants to merge 17 commits into from
Closed

Fix --output-document flag #8121

wants to merge 17 commits into from

Conversation

amaury1093
Copy link
Contributor

Description

ref: #8109


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@amaury1093 amaury1093 mentioned this pull request Dec 9, 2020
6 tasks
@amaury1093 amaury1093 marked this pull request as ready for review December 9, 2020 14:24
@amaury1093 amaury1093 marked this pull request as draft December 9, 2020 14:28
@alessio
Copy link
Contributor

alessio commented Dec 9, 2020

@amaurymartiny -> #8122 - please take a look

handle deferred io.WriterCloser.Close() calls
@@ -60,11 +60,11 @@ account key. It implies --signature-only.
}

func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is wayyyy to large for naked returns. If using named return value(s), please avoid naked returns and explicitly return the value(s).

amaury1093 and others added 2 commits December 9, 2020 16:05
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
@alessio
Copy link
Contributor

alessio commented Dec 9, 2020

I've made a couple of corrections @alexanderbez. The naked returns allow the function to return the error returned by a -*File.Close() call in case no write errors were reported before. There is only one return value. So thought that the impact on readability wouldn't be too big. Wdyt?

(There is an excellent article that illustrates the pattern that I used and its rationale: https://www.joeshaw.org/dont-defer-close-on-writable-files/#:~:text=But%20this%20idiom%20is%20actually,infrequent%2C%20maddening%20bugs%20will%20occur.)

@alexanderbez
Copy link
Contributor

I do not understand. It's as simple as return err. Please do not use naked returns. I don't want to read the code and guess what err is.

@alessio
Copy link
Contributor

alessio commented Dec 9, 2020

@amaurymartiny I had a chat with bez. My code suggestions should both just work and make him happy

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
amaury1093 and others added 9 commits December 9, 2020 16:45
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
@amaury1093
Copy link
Contributor Author

Weird error Unregistered interface types.PubKey, adding a codec.RegisterCrypto(clientCtx.LegacyAmino) solves it, but I'll investigate a bit why it's not registered upstream already.

s.Require().NoError(err)
defer func() {
err = os.Remove(tempfile.Name())
s.Require().NoError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This may cause the test to fail if the temporary file is not deleted successfully at the end of the test (which might happen for a number of reasons that are entirely unrelated to the test case itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, what are best practices here? should I just ignore the err?

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not know if I agree with this. I would keep this as-is. If it errors, so be it. Just rerun the test. Ignoring errors in tests is typically not something you want to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is about the removal of a temporary file that is created within the execution of a test. If we want to go for The Right Way(c), then yes we might want to cause the test fail. Though weird things happen in a CI that we don't fully control, e.g. resources might become unavailable before the program exits. In my opinion, it'd just be a self-inflicted pain in the lower back if we had to go and manually re-run all tests because of a glitch in the CI. Thus we should just ignore the error and let go.

Copy link
Contributor Author

@amaury1093 amaury1093 Dec 9, 2020

Choose a reason for hiding this comment

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

Solved with #8121 (comment), I guess.

@amaury1093
Copy link
Contributor Author

OK i realized that @robert-zaremba already fixed this in #8106. Talked offline with Robert, i'll close this and let's continue there.

@amaury1093 amaury1093 closed this Dec 9, 2020
@amaury1093 amaury1093 deleted the am-8109-fix-output-doc branch December 9, 2020 17:28
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.

3 participants