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

[Merged by Bors] - chore: refactor panics into error handling #6345

Closed
wants to merge 4 commits into from

Conversation

fasmat
Copy link
Member

@fasmat fasmat commented Sep 23, 2024

Motivation

Updated some places where log.Panic is used and replaced it by returning the error, callers already handle them.

Description

Return errors in some places where log.Panic was used before

Test Plan

Existing tests pass.

TODO

  • Explain motivation or link existing issue(s)
  • Test changes and document test plan
  • Update documentation as needed
  • Update changelog as needed

@fasmat fasmat self-assigned this Sep 23, 2024
@fasmat fasmat changed the title Refactor panics into error handling chore: refactor panics into error handling Sep 23, 2024
Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 81.7%. Comparing base (062d40c) to head (0c0ca05).
Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
node/node.go 50.0% 2 Missing and 2 partials ⚠️
fetch/fetch.go 66.6% 1 Missing and 1 partial ⚠️
activation/poetdb.go 66.6% 1 Missing ⚠️
fetch/cache.go 66.6% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #6345     +/-   ##
=========================================
- Coverage     81.7%   81.7%   -0.1%     
=========================================
  Files          312     312             
  Lines        34637   34657     +20     
=========================================
+ Hits         28327   28331      +4     
- Misses        4479    4489     +10     
- Partials      1831    1837      +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

fetch/fetch.go Outdated Show resolved Hide resolved
fetch/fetch.go Outdated
bs := datastore.NewBlobStore(cdb, proposals)

hashPeerCache, err := NewHashPeersCache(cacheSize)
if err != nil {
return nil, fmt.Errorf("create hash peer cache: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, propagating this up isn't the right choice. It can only fail if the private cacheSize const is invalid so the problem is:

  • a clear programmer error
  • entirely isolated to this pkg/file

I think it's totally fine to panic on it rather than complicating other code with an impossible (in normal conditions, when cacheSize >=0 invariant isn't violated) error, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I changed it to panic, but left the changes regarding returning an error from NewFetch in the case this config option isn't a constant in the future (at which point I'd prefer returning an error instead of panicing).

@fasmat
Copy link
Member Author

fasmat commented Sep 24, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Sep 24, 2024
## Motivation

Updated some places where `log.Panic` is used and replaced it by returning the error, callers already handle them.
@spacemesh-bors
Copy link

Build failed:

  • systest-status

@fasmat
Copy link
Member Author

fasmat commented Sep 24, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Sep 24, 2024
## Motivation

Updated some places where `log.Panic` is used and replaced it by returning the error, callers already handle them.
@spacemesh-bors
Copy link

Build failed:

@fasmat
Copy link
Member Author

fasmat commented Sep 24, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Sep 24, 2024
## Motivation

Updated some places where `log.Panic` is used and replaced it by returning the error, callers already handle them.
@spacemesh-bors
Copy link

Build failed:

  • systest-status

@fasmat
Copy link
Member Author

fasmat commented Sep 24, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Sep 24, 2024
## Motivation

Updated some places where `log.Panic` is used and replaced it by returning the error, callers already handle them.
@spacemesh-bors
Copy link

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title chore: refactor panics into error handling [Merged by Bors] - chore: refactor panics into error handling Sep 24, 2024
@spacemesh-bors spacemesh-bors bot closed this Sep 24, 2024
@spacemesh-bors spacemesh-bors bot deleted the avoid-panics branch September 24, 2024 14:06
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.

2 participants