Skip to content

[Utility] Leverage Pocket Errors in the entire codebase #556

@Olshansk

Description

@Olshansk

Objective

Leverage pocket specific error codes throughout the entire codebase.

Origin Document

utility/types/error.go defines error codes and messages that will return descriptive identifiers to the user. These are currently only part of the utility module and cannot be used outside of it.

In #550, we moved transaction.proto from utility to shared which prevented the use of these shared errors.

type Code float64

//nolint:gosec // G101 - Not hard-coded credentials
const (
	CodeOK                               Code = 0
	CodeEmptyTransactionError            Code = 2
	CodeInvalidSignerError               Code = 3
	CodeDecodeMessageError               Code = 4
    // ...
}

const (
	GetStakedAmountsError             = "an error occurred getting the validator's amount staked"
	SetValidatorStakedAmountError     = "an error occurred setting the validator' amount staked"
	EqualVotesError                   = "the votes are identical and not equivocating"
	UnequalRoundsError                = "the round numbers are not equal"
	UnequalVoteTypesError             = "the vote types are not equal"
    // ...
}

// ...

func ErrUnknownParam(paramName string) Error {
	return NewError(CodeUnknownParamError, fmt.Sprintf("%s: %s", UnknownParamError, paramName))
}

func ErrUnequalPublicKeys() Error {
	return NewError(CodeUnequalPublicKeysError, UnequalPublicKeysError)
}

// ...

Goals

  • Design a way for Pocket specific error messages & codes to be utilised throughout the entire codebase
  • Enable other developers to easily add new errors or modify existing ones
  • Make it clear to the end user what the error is

Deliverable

Non-goals / Non-deliverables

  • Updating all errors throughout the entire codebase to return pocket specific error codes

General issue deliverables

  • Update the appropriate CHANGELOG(s)
  • Update any relevant local/global README(s)
  • Update relevant source code tree explanations
  • Add or update any relevant or supporting mermaid diagrams

Testing Methodology

  • All tests: make test_all
  • LocalNet: verify a LocalNet is still functioning correctly by following the instructions at docs/development/README.md

Creator: @Olshansk
Co-Owners: @deblasis

Metadata

Metadata

Assignees

Labels

code healthNice to have code improvementcoreCore infrastructure - protocol relatedutilityUtility specific changes

Type

No type

Projects

Status

Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions