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

Closed
4 tasks
vinayak0035 opened this issue Oct 18, 2024 · 4 comments · Fixed by #1201
Closed
4 tasks

Add Error Handling in GetBridgeDBInstance Function #1196

vinayak0035 opened this issue Oct 18, 2024 · 4 comments · Fixed by #1201
Labels

Comments

@vinayak0035
Copy link
Contributor

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 {
	bridgeDBOnce.Do(func() {
		var err error
		bridgeDB, err = leveldb.OpenFile(filePath, nil)
		if err != nil {
			log.Fatalln("Error in Bor Opening Database", err.Error())
		}
	})
	return bridgeDB
}

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
Contributor Author

@Raneet10 PR: #1198

@vinayak0035
Copy link
Contributor Author

@Raneet10 @pratikspatil024 New PR: #1201

Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants
@Raneet10 @pratikspatil024 @vinayak0035 and others