Error codes

Explanation of what error codes are and how to handle them in your code

Introduction

Like Compound, just because a transaction was successful does not mean it actually did what we expected. Cozy inherited some of Compound's error handling approaches, which means a transaction may be successful—and show as successful on Etherscan and other block explorers—but in reality it didn't succeed. This is because some failed transactions will return an error code and emit a Failure event instead of reverting. You can find Compound's error codes here, and a brief history of why it's handled this way here.

This approach can be a bit tedious for users and developers, as we now we have to manually ensure our transaction succeeded before continuing to the next step. In the Cozy Developer Guides repo you'll find a method called findLog() in the utils/utils.ts folder to help you with this.

This method searches for the expected success log in a transaction and returns it if found. If it's not found, an error is thrown and the Failure error codes are reported. You can compare those error codes to those in the table below to learn why your transaction failed.

Error codes are defined in ErrorReporter.sol and provided here for convenience.

Comptroller

If an error code was emitted from a transaction to the Comptroller, refer to these error codes.

Error Codes

Error codes 0–17 are identical to Compound's. Error codes 18 and 19 are unique to Cozy.

CodeNameDescription

0

NO_ERROR

Not a failure

1

UNAUTHORIZED

The sender is not authorized to perform this action.

2

COMPTROLLER_MISMATCH

Liquidation cannot be performed in markets with different comptrollers.

3

INSUFFICIENT_SHORTFALL

The account does not have sufficient shortfall to perform this action.

4

INSUFFICIENT_LIQUIDITY

The account does not have sufficient liquidity to perform this action.

5

INVALID_CLOSE_FACTOR

The close factor is not valid.

6

INVALID_COLLATERAL_FACTOR

The collateral factor is not valid.

7

INVALID_LIQUIDATION_INCENTIVE

The liquidation incentive is invalid.

8

MARKET_NOT_ENTERED

The market has not been entered by the account.

9

MARKET_NOT_LISTED

The market is not currently listed by the comptroller.

10

MARKET_ALREADY_LISTED

An admin tried to list the same market more than once.

11

MATH_ERROR

A math calculation error occurred.

12

NONZERO_BORROW_BALANCE

The action cannot be performed since the account carries a borrow balance.

13

PRICE_ERROR

The comptroller could not obtain a required price of an asset.

14

REJECTION

The comptroller rejects the action requested by the market.

15

SNAPSHOT_ERROR

The comptroller could not get the account borrows and exchange rate from the market.

16

TOO_MANY_ASSETS

Attempted to enter more markets than are currently supported.

17

TOO_MUCH_REPAY

Attempted to repay more than is allowed by the protocol.

18

INVALID_TRIGGER

The Protection Market cannot be created because the trigger is not a valid trigger, or was already triggered

19

PROTECTION_MARKET_FACTORY_ERROR

The admin tried to set the Protection Market Factory to an invalid contract

Failure Info

TODO

Cozy Token

If an error code was emitted from a transaction to a Cozy Token, refer to these error codes.

Error Codes

CodeDescription

0

NO_ERROR

1

UNAUTHORIZED

2

BAD_INPUT

3

COMPTROLLER_REJECTION

4

COMPTROLLER_CALCULATION_ERROR

5

INTEREST_RATE_MODEL_ERROR

6

INVALID_ACCOUNT_PAIR

7

INVALID_CLOSE_AMOUNT_REQUESTED

8

INVALID_COLLATERAL_FACTOR

9

MATH_ERROR

10

MARKET_NOT_FRESH

11

MARKET_NOT_LISTED

12

TOKEN_INSUFFICIENT_ALLOWANCE

13

TOKEN_INSUFFICIENT_BALANCE

14

TOKEN_INSUFFICIENT_CASH

15

TOKEN_TRANSFER_IN_FAILED

16

TOKEN_TRANSFER_OUT_FAILED

17

INVALID_GUARDIAN

Failure Info

TODO

Protection Market Factory

If an error code was emitted from a transaction to the Protection Market Factory, refer to these error codes.

Error Codes

CodeNameDescription

0

NO_ERROR

1

UNAUTHORIZED

2

INTEREST_RATE_MODEL_ERROR

Failure Info

TODO

Oracle

If an error code was emitted from a transaction to the Oracle, refer to these error codes.

Error Codes

CodeNameDescription

0

NO_ERROR

1

UNAUTHORIZED

Failure Info

TODO

Last updated