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

Add Error Handling in GetBridgeDBInstance Function #1196

Open
4 tasks
vinayak0035 opened this issue Oct 18, 2024 · 2 comments
Open
4 tasks

Add Error Handling in GetBridgeDBInstance Function #1196

vinayak0035 opened this issue Oct 18, 2024 · 2 comments

Comments

@vinayak0035
Copy link

vinayak0035 commented Oct 18, 2024

Summary

Implement error handling in the GetBridgeDBInstance function to handle cases where the bridgeDB object is nil.

Problem Definition

Currently, the GetBridgeDBInstance function does not handle scenarios where bridgeDB may be nil. If the database fails to open for any reason, returning a nil object can lead to potential runtime panics or errors when the returned database instance is used. Adding error handling will help prevent these issues and improve the robustness of the code.

Benefits of including this feature include:

  • Enhanced reliability of the application.
  • Easier debugging by providing clear error messages.
  • Improved user experience by avoiding crashes due to nil references.

Proposal

Modify the GetBridgeDBInstance function to include error handling. The implementation could look like this:

https://github.com/maticnetwork/heimdall/blob/master/bridge/setu/util/db.go#L16

func GetBridgeDBInstance(filePath string) (*leveldb.DB, error) {
	var err error
	bridgeDBOnce.Do(func() {
		bridgeDB, err = leveldb.OpenFile(filePath, nil)
	})

	if err != nil {
		return nil, err // Return nil and the error
	}

	return bridgeDB, nil // Return the database instance
}

This change ensures that the function returns an error if the database fails to open, allowing the caller to handle it appropriately.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@Raneet10
Copy link
Member

Hey @vinayak0035 thanks for flagging this! Could you maybe open a PR for this ?

@vinayak0035
Copy link
Author

@Raneet10 PR: #1198

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

No branches or pull requests

2 participants