Skip to content

Commit

Permalink
refactor: optimize errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adu-web3 committed Sep 23, 2024
1 parent 8429a2f commit befeed8
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/native_deposit_workflow.wsd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ start

:Get the capsule associated with the message sender;
if (capsule == address(0)) then (yes)
:Revert with CapsuleNotExist error;
:Revert with CapsuleDoesNotExist error;
stop
endif

Expand Down
2 changes: 1 addition & 1 deletion src/core/ExocoreGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ contract ExocoreGateway is
(bool success, bytes memory responseOrReason) =
address(this).call(abi.encodePacked(selector_, abi.encode(_origin.srcEid, _origin.nonce, act, payload)));
if (!success) {
revert Errors.RequestExecuteFailed(act, _origin.nonce, responseOrReason);
revert Errors.RequestOrResponseExecuteFailed(act, _origin.nonce, responseOrReason);
}

// decode to get the response, and send it back if it is not empty
Expand Down
12 changes: 2 additions & 10 deletions src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ library Errors {
error BootstrapValidatorNameLengthZero();

/// @dev Indicates an operation failed because the specified vault does not exist.
error VaultNotExist();
error VaultDoesNotExist();

/// @dev Indicates that an operation which is not yet supported is requested.
error NotYetSupported();
Expand Down Expand Up @@ -157,7 +157,7 @@ library Errors {
/// @dev ClientChainGateway: token addition must happen via Exocore
error ClientChainGatewayTokenAdditionViaExocore();
/// @notice Error thrown when the ExoCapsule does not exist.
error CapsuleNotExist();
error CapsuleDoesNotExist();

//////////////////////////////////////
// ClientGatewayLzReceiver Errors //
Expand Down Expand Up @@ -235,12 +235,6 @@ library Errors {
/// @dev thrown when dissociateOperatorFromEVMStaker failed
error DissociateOperatorFailed(uint32 clientChainId, address staker);

/// @notice Thrown when the execution of a request fails
/// @param act The action that failed.
/// @param nonce The LayerZero nonce.
/// @param reason The reason for the failure.
error RequestExecuteFailed(Action act, uint64 nonce, bytes reason);

/// @notice Thrown when the execution of a precompile call fails.
/// @param selector_ The function selector of the precompile call.
/// @param reason The reason for the failure.
Expand Down Expand Up @@ -275,8 +269,6 @@ library Errors {
/// @notice Thrown when the whitelist tokens list is too long.
error WhitelistTokensListTooLong();

error MismatchMessageHanlder();

////////////////////////////////////////
// NativeRestakingController Errors //
////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/storage/BootstrapStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ contract BootstrapStorage is GatewayStorage {
function _getVault(address token) internal view returns (IVault) {
IVault vault = tokenToVault[token];
if (address(vault) == address(0)) {
revert Errors.VaultNotExist();
revert Errors.VaultDoesNotExist();
}
return vault;
}
Expand Down
2 changes: 1 addition & 1 deletion src/storage/ClientChainGatewayStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ contract ClientChainGatewayStorage is BootstrapStorage {
function _getCapsule(address owner) internal view returns (IExoCapsule) {
IExoCapsule capsule = ownerToCapsule[owner];
if (address(capsule) == address(0)) {
revert Errors.CapsuleNotExist();
revert Errors.CapsuleDoesNotExist();
}
return capsule;
}
Expand Down
4 changes: 2 additions & 2 deletions test/foundry/unit/ClientChainGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ contract WithdrawNonBeaconChainETHFromCapsule is SetUp {
address payable userWithoutCapsule = payable(address(0x123));

vm.prank(userWithoutCapsule);
vm.expectRevert(Errors.CapsuleNotExist.selector);
vm.expectRevert(Errors.CapsuleDoesNotExist.selector);
clientGateway.withdrawNonBeaconChainETHFromCapsule(userWithoutCapsule, withdrawAmount);
}

Expand Down Expand Up @@ -394,7 +394,7 @@ contract WithdrawalPrincipalFromExocore is SetUp {
function test_revert_withdrawVirtualStakedETH() public {
// Try to withdraw VIRTUAL_STAKED_ETH
vm.prank(user);
vm.expectRevert(Errors.VaultNotExist.selector);
vm.expectRevert(Errors.VaultDoesNotExist.selector);
clientGateway.withdrawPrincipalFromExocore(VIRTUAL_STAKED_ETH_ADDRESS, WITHDRAWAL_AMOUNT);
}

Expand Down
2 changes: 1 addition & 1 deletion test/mocks/ExocoreGatewayMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ contract ExocoreGatewayMock is
(bool success, bytes memory responseOrReason) =
address(this).call(abi.encodePacked(selector_, abi.encode(_origin.srcEid, _origin.nonce, act, payload)));
if (!success) {
revert Errors.RequestExecuteFailed(act, _origin.nonce, responseOrReason);
revert Errors.RequestOrResponseExecuteFailed(act, _origin.nonce, responseOrReason);
}

emit MessageExecuted(act, _origin.nonce);
Expand Down

0 comments on commit befeed8

Please sign in to comment.