pocket icon indicating copy to clipboard operation
pocket copied to clipboard

[Utility] Leverage Pocket Errors in the entire codebase

Open Olshansk opened this issue 1 year ago • 2 comments

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

  • [ ] A PR that moves errors.go in utility into a shared directory
  • [ ] Update to transaction.go and transaction_test.go in shared that revert it to parity with what we had before #550

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

Olshansk avatar Feb 28 '23 00:02 Olshansk