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

Removing errors package #315

Closed
18 of 19 tasks
themantre opened this issue Apr 28, 2022 · 1 comment · Fixed by #1425, #1454, #1457, #1503 or #1504
Closed
18 of 19 tasks

Removing errors package #315

themantre opened this issue Apr 28, 2022 · 1 comment · Fixed by #1425, #1454, #1457, #1503 or #1504
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@themantre
Copy link
Contributor

themantre commented Apr 28, 2022

The errors package is intended for defining code specific to each error. However, there are a few issues with this approach:

  • It is not feasible to define code for every possible error.
  • The errors package becomes burdened with knowledge about all errors, which is considered an anti-pattern.

A more effective approach would be to define errors within their respective packages and ensure they are decoupled from one another.

The following packages will need to be updated to define errors locally:

  • types/account
  • types/block
  • types/certificate
  • types/proposal
  • types/tx
  • types/validator
  • types/vote
  • consensus
  • committee
  • crypto
  • execution
  • network
  • sandbox
  • sortition
  • state
  • store
  • sync
  • txpool
  • wallet

Proposed Changes:

1- Define errors directly in each package where they are used.
2- Update error handling and tests in each package to refer to the errors defined locally rather than in utils/errors.
3- Consider creating a <package>/errors.go file that exports any errors that need to be shared across multiple packages. But each package still owns its own errors.

This change will make error handling cleaner and tests more self-contained by defining errors alongside the code that uses them. It removes unnecessary coupling between packages introduced by centralizing errors.

Once all errors have been converted, we can close this issue.

@themantre themantre added the enhancement New feature or request label Apr 28, 2022
@jwmdev jwmdev self-assigned this Sep 4, 2022
@b00f b00f unassigned jwmdev Jun 7, 2023
@b00f
Copy link
Collaborator

b00f commented Aug 22, 2023

This post describes the conventional way to define errors in Golang: https://travix.io/errors-derived-from-constants-in-go-fda6748b4072

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment