errors.sol
Overview
The errors.sol file defines an abstract contract named Errors that serves as a centralized repository of error codes used throughout the system. These error codes are represented as constant unsigned 16-bit integers (uint16) and provide a standardized way to identify specific error conditions programmatically. The contract also includes a version string versionErrors to track the version of the error code definitions.
This approach facilitates consistent error handling and reporting across different smart contracts or components in the system by referencing predefined error codes instead of using arbitrary values or strings.
Contract: Errors
Declaration
abstract contract Errors {
string constant versionErrors = "6.2.0";
// Numerous uint16 constant error codes follow...
}
The contract is marked as
abstractmeaning it is not intended to be deployed on its own but to be inherited or referenced by other contracts.The
versionErrorsstring provides version tracking for the error list, useful for compatibility and upgrade management.
Error Code Constants
The contract declares a comprehensive list of error codes as uint16 constants. Each constant has a unique numerical value and a descriptive name indicating the nature of the error condition it represents.
Structure and Naming
Each constant starts with the prefix
ERR_followed by an uppercase descriptive name, e.g.,ERR_NO_SALT,ERR_SENDER_NOT_DAO.The error codes start at
200and increment almost sequentially, with some gaps, up to302.There is a special code
NOT_ERRwith value223that likely represents a "no error" or "not an error" state.
Usage
Other contracts or modules can reference these constants to:
Return specific error codes upon failure.
Compare error codes in conditional logic.
Emit events or logs with standardized error codes.
Improve readability and maintainability by avoiding magic numbers.
Examples
// Example: Returning an error code when sender is not authorized
function someFunction() public returns (uint16) {
if (msg.sender != daoAddress) {
return ERR_SENDER_NOT_DAO; // Value 202
}
// Normal function logic
return NOT_ERR; // No error
}
// Example: Checking error code returned from a call
uint16 errorCode = externalContract.someFunction();
if (errorCode == ERR_LOW_BALANCE) {
// Handle low balance error
}
Selected Error Codes and Their Possible Meanings
Constant Name | Code | Description (Inferred) |
|---|---|---|
| 200 | Missing or invalid salt value in operation |
| 202 | Sender is not authorized DAO entity |
| 203 | Root key is zero or uninitialized |
| 204 | Provided value is too low |
| 205 | Not the root repository |
| 209 | Duplicate message detected |
| 212 | Operation attempted by non-owner |
| 213 | Referenced branch does not exist |
| 216 | Exceeded allowed number of parent entities |
| 222 | Invalid name format or value |
| 223 | Special code indicating no error |
| 225 | Wallet does not exist |
| 266 | Exceeded allowed number of tags |
| 268 | Minting is not allowed in the current context |
| 273 | Exceeded maximum number of proposals |
| 300 | Wallet is currently busy or locked |
| 302 | Penalty (slash) has already been applied |
This list is not exhaustive; the file contains many more error codes covering a wide range of possible failure or invalid states related to authorization, data integrity, state conditions, and business logic constraints.
Implementation Details
Constant Storage: Using
uint16constants for error codes minimizes storage size and gas costs compared to string-based errors.Versioning: The version string allows tracking which set of errors is in use, useful when contracts evolve and error codes may be added or deprecated.
Abstract Contract: By declaring the contract as abstract, it enforces that
Errorsis a utility base from which other contracts can inherit or import these constants without deploying this contract itself.No Functions: This contract only defines constants and does not implement any functions or modifiers.
Interaction with Other System Components
Error Reporting: Other smart contracts within the system import or inherit
Errorsto use these error constants when performing checks and validations.Consistency: By centralizing error codes, all parts of the system have a single source of truth for error handling, reducing discrepancies and improving debugging.
Upgradeability: When updating or extending the system, new error codes can be appended to this contract and referenced accordingly.
Integration: Components like DAOs, wallets, repositories, and governance modules likely use these error codes based on the naming conventions.
For more context on error handling and best practices for error codes in smart contracts, see Error Handling in Smart Contracts.
Mermaid Diagram
classDiagram
class Errors {
+string versionErrors
+uint16 ERR_NO_SALT
+uint16 ERR_SENDER_NOT_DAO
+uint16 ERR_ZERO_ROOT_KEY
+uint16 ERR_LOW_VALUE
+uint16 ERR_NOT_OWNER
+uint16 ERR_BRANCH_NOT_EXIST
+uint16 ERR_TOO_MANY_PARENTS
+uint16 NOT_ERR
+uint16 ERR_WALLET_NOT_EXIST
+uint16 ERR_TOO_MANY_TAGS
+uint16 ERR_NOT_ALLOW_MINT
+uint16 ERR_TOO_MANY_PROPOSALS
+uint16 ERR_WALLET_BUSY
+uint16 ERR_ALREADY_SLASH
}
The diagram illustrates that the Errors contract contains multiple constant properties representing error codes and a version string. No methods are defined.