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

refactor!: Remove panics #500

Merged
merged 21 commits into from
Jun 1, 2022
Merged

refactor!: Remove panics #500

merged 21 commits into from
Jun 1, 2022

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented May 5, 2022

WIP, removing some panics by returning errors instead. Looking to solve #212

@facundomedica facundomedica changed the title refactor!: Remove panic refactor!: Remove panics May 5, 2022
@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 5, 2022

This pull request introduces 2 alerts when merging adbf40d into dfde9a5 - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@ValarDragon
Copy link
Contributor

Thanks for working on this!

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 5, 2022

This pull request introduces 2 alerts when merging 2886aa5 into dfde9a5 - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@facundomedica
Copy link
Member Author

From the starting 49 panics we are now at 25.
7 are in *_test.go so won't be paying too much attention on those
4 are in ProofOp has to comply with an interface
2 there are tests in place to ensure that these panic (not sure if we want to remove those)

So 12 panics to go 🥳

I think I should be able to finish this up tomorrow, but I expect a lot of back and forth. I assume we might encounter cases in which we might go back to panics, but I can't tell.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 5, 2022

This pull request introduces 1 alert when merging c95063a into dfde9a5 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@robert-zaremba
Copy link
Collaborator

I'm in a full support for reducing panics. However, this will create lot of breaking changes in Cosmos SDK. So this has to be well coordinated.

@facundomedica
Copy link
Member Author

I'll put this as R4R, I'm missing the panics in KeyFormat but maybe it's better to do those in a different PR. This is getting too big and the KeyFormat methods seem to be everywhere

@facundomedica facundomedica marked this pull request as ready for review May 9, 2022 18:17
Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

utACK

fmt.Printf("Hash: %X\n", tree.Hash())
hash, err := tree.Hash()
if err != nil {
fmt.Fprintf(os.Stderr, "Error hashing tree: %s\n", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not using log package?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's because it's a command that prints stuff to the command line output. So it uses fmt.Print everywhere

node.go Outdated
if node.isLeaf() {
panic("Attempt to copy a leaf node")
return nil, fmt.Errorf("attempt to copy a leaf node")
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's create const errors and return them.
eg:

const ErrCloneLeafNode = fmt.Errorf("attempt to copy a leaf node")

Copy link
Member Author

Choose a reason for hiding this comment

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

Added them everywhere I replaced a panic (and the error is not dynamic). More work will be needed on this later on

@tac0turtle
Copy link
Member

this looks amazing!!

@tac0turtle tac0turtle merged commit abaaacd into cosmos:master Jun 1, 2022
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.

4 participants