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: improve error handling in LoadTxInfo #1571

Open
wants to merge 5 commits into
base: v0.34.x-celestia
Choose a base branch
from

Conversation

tiendn
Copy link
Contributor

@tiendn tiendn commented Dec 20, 2024

Description

Improve error handling in LoadTxInfo

Replace panic with proper error returns in LoadTxInfo function to follow Go's
error handling conventions. This change:

  • Adds input validation for empty transaction hash
  • Returns descriptive error messages instead of panicking
  • Wraps underlying errors with context
  • Maintains backward compatibility with nil returns for not found cases

This is part of an ongoing effort to improve error handling patterns in the
codebase.

PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use
    unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@tiendn tiendn requested a review from a team as a code owner December 20, 2024 10:57
@tiendn tiendn requested review from cmwaters and rach-id and removed request for a team December 20, 2024 10:57
@tiendn tiendn closed this Dec 20, 2024
@tiendn tiendn reopened this Dec 20, 2024
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Overall I'm a fan of replacing panics with errors so thanks!

What motivated this PR? Is this related to a GitHub issue in the repo?

Before approving, it would be nice to add some unit tests that check for the new errors.

store/store.go Show resolved Hide resolved
store/store.go Outdated Show resolved Hide resolved
store/store.go Outdated
}
if len(bz) == 0 {
return nil
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] should we return an error in this situation? Also needs a unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think it makes consistent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This still doesn't return an error. should it?

@rootulp rootulp changed the title fix: improve error handling in LoadTxInfo refactor: improve error handling in LoadTxInfo Dec 20, 2024
@celestia-bot celestia-bot requested a review from rootulp December 20, 2024 16:24
@tiendn
Copy link
Contributor Author

tiendn commented Dec 20, 2024

What motivated this PR? Is this related to a GitHub issue in the repo?

Yeah, i want to improve codebase

@rootulp rootulp marked this pull request as draft December 20, 2024 16:26
@tiendn tiendn marked this pull request as ready for review December 20, 2024 16:43
@tiendn
Copy link
Contributor Author

tiendn commented Dec 23, 2024

I'll fixed test

@tiendn tiendn closed this Dec 23, 2024
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Thanks for adding unit test! One last question about returning (nil, nil) instead of an error for the not found case.

store/store.go Outdated Show resolved Hide resolved
store/store.go Outdated
}
if len(bz) == 0 {
return nil
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still doesn't return an error. should it?

store/store_test.go Outdated Show resolved Hide resolved
store/store_test.go Outdated Show resolved Hide resolved
store/store_test.go Outdated Show resolved Hide resolved
@tiendn tiendn reopened this Dec 23, 2024
@celestia-bot celestia-bot requested a review from rootulp December 23, 2024 17:25
@tiendn
Copy link
Contributor Author

tiendn commented Dec 23, 2024

Hi @rootulp, thank you for reviewing my PR.
I've updated the error msg in case of not found. Please check

store/store_test.go Outdated Show resolved Hide resolved
store/store_test.go Outdated Show resolved Hide resolved
store/store_test.go Outdated Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from rootulp December 24, 2024 02:26
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Build is failing

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