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

nit: panic with error #4741

Merged
merged 12 commits into from
Sep 22, 2023
Merged

nit: panic with error #4741

merged 12 commits into from
Sep 22, 2023

Conversation

crodriguezvega
Copy link
Contributor

Description

closes: #XXXX

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


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 and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@chatton
Copy link
Contributor

chatton commented Sep 21, 2023

Doing a quick search I noticed we are relatively inconsistent with panicking on strings vs errors, maybe we could turn them all into errors? Looks like a ~20+ panics using strings

@DimitrisJim
Copy link
Contributor

For the instances @chatton mentions: grep -inr "panic(\"" . --include="*.go should find them

@chatton
Copy link
Contributor

chatton commented Sep 21, 2023

@DimitrisJim with next level grep-fu as usual :D

@crodriguezvega crodriguezvega added the type: code hygiene Clean up code but without changing functionality or interfaces label Sep 21, 2023
modules/core/02-client/keeper/keeper.go Fixed Show fixed Hide fixed
@@ -56,7 +56,7 @@
func (h Height) Compare(other exported.Height) int64 {
height, ok := other.(Height)
if !ok {
panic(fmt.Sprintf("cannot compare against invalid height type: %T. expected height type: %T", other, h))
panic(fmt.Errorf("cannot compare against invalid height type: %T. expected height type: %T", other, h))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -178,7 +178,7 @@
revision, err := strconv.ParseUint(splitStr[len(splitStr)-1], 10, 64)
// sanity check: error should always be nil since regex only allows numbers in last element
if err != nil {
panic(fmt.Sprintf("regex allowed non-number value as last split element for chainID: %s", chainID))
panic(fmt.Errorf("regex allowed non-number value as last split element for chainID: %s", chainID))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2023

Codecov Report

Merging #4741 (cbeea4b) into main (9b595a9) will not change coverage.
Report is 1 commits behind head on main.
The diff coverage is 22.35%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4741   +/-   ##
=======================================
  Coverage   79.49%   79.49%           
=======================================
  Files         189      189           
  Lines       13285    13285           
=======================================
  Hits        10561    10561           
  Misses       2296     2296           
  Partials      428      428           
Files Changed Coverage Δ
...7-interchain-accounts/controller/ibc_middleware.go 73.00% <0.00%> (ø)
...7-interchain-accounts/controller/keeper/genesis.go 93.54% <0.00%> (ø)
...interchain-accounts/controller/keeper/handshake.go 89.85% <0.00%> (ø)
...ps/27-interchain-accounts/host/keeper/handshake.go 89.39% <0.00%> (ø)
modules/apps/27-interchain-accounts/module.go 49.50% <0.00%> (ø)
.../apps/27-interchain-accounts/simulation/decoder.go 84.61% <0.00%> (ø)
modules/apps/29-fee/keeper/escrow.go 92.81% <0.00%> (ø)
modules/apps/transfer/keeper/genesis.go 92.59% <0.00%> (ø)
modules/apps/transfer/keeper/relay.go 91.00% <0.00%> (ø)
modules/apps/transfer/module.go 44.06% <0.00%> (ø)
... and 18 more

@@ -425,7 +426,7 @@
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.ParamsKey))
if bz == nil { // only panic on unset params and not on empty params
panic("client params are not set in store")
panic(errors.New("client params are not set in store"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -52,99 +54,99 @@

// ClientType panics!
func (ClientState) ClientType() string {
panic("legacy solo machine is deprecated!")
panic(errors.New("legacy solo machine is deprecated"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// Status panics!
func (ClientState) Status(_ sdk.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status {
panic("legacy solo machine is deprecated!")
panic(errors.New("legacy solo machine is deprecated"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// UpdateState panis!
func (*ClientState) UpdateState(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) []exported.Height {
panic("legacy solo machine is deprecated!")
panic(errors.New("legacy solo machine is deprecated"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

LGTM! I see 2 more in

callbacks/ibc_go_middleware_test.go

@crodriguezvega
Copy link
Contributor Author

LGTM! I see 2 more in

callbacks/ibc_go_middleware_test.go

Yeah, I am going to leave those two. They are in tests, I don't think we need to be that consistent. :)

@crodriguezvega crodriguezvega merged commit 65dd3ae into main Sep 22, 2023
63 checks passed
@crodriguezvega crodriguezvega deleted the carlos/nit-panic-with-error branch September 22, 2023 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code hygiene Clean up code but without changing functionality or interfaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants