Add custom errors to docs (#4480)

This commit is contained in:
Ernesto García
2023-07-27 17:18:45 -06:00
committed by GitHub
parent 9445f96223
commit 02ea01765a
5 changed files with 47 additions and 11 deletions

View File

@ -58,8 +58,7 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
/** /**
* @dev Modifier that checks that an account has a specific role. Reverts * @dev Modifier that checks that an account has a specific role. Reverts
* with a custom error including the required role. * with an {AccessControlUnauthorizedAccount} error including the required role.
*
*/ */
modifier onlyRole(bytes32 role) { modifier onlyRole(bytes32 role) {
_checkRole(role); _checkRole(role);
@ -81,15 +80,16 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
} }
/** /**
* @dev Revert with a custom error if `_msgSender()` is missing `role`. * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* Overriding this function changes the behavior of the {onlyRole} modifier. * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/ */
function _checkRole(bytes32 role) internal view virtual { function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender()); _checkRole(role, _msgSender());
} }
/** /**
* @dev Revert with a custom error if `account` is missing `role`. * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/ */
function _checkRole(bytes32 role, address account) internal view virtual { function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) { if (!hasRole(role, account)) {

View File

@ -8,18 +8,21 @@ These interfaces are available as `.sol` files, and also as compiler `.json` ABI
are useful to interact with third party contracts that implement them. are useful to interact with third party contracts that implement them.
- {IERC20} - {IERC20}
- {IERC20Errors}
- {IERC20Metadata} - {IERC20Metadata}
- {IERC165} - {IERC165}
- {IERC721} - {IERC721}
- {IERC721Receiver} - {IERC721Receiver}
- {IERC721Enumerable} - {IERC721Enumerable}
- {IERC721Metadata} - {IERC721Metadata}
- {IERC721Errors}
- {IERC777} - {IERC777}
- {IERC777Recipient} - {IERC777Recipient}
- {IERC777Sender} - {IERC777Sender}
- {IERC1155} - {IERC1155}
- {IERC1155Receiver} - {IERC1155Receiver}
- {IERC1155MetadataURI} - {IERC1155MetadataURI}
- {IERC1155Errors}
- {IERC1271} - {IERC1271}
- {IERC1363} - {IERC1363}
- {IERC1363Receiver} - {IERC1363Receiver}
@ -40,6 +43,12 @@ are useful to interact with third party contracts that implement them.
== Detailed ABI == Detailed ABI
{{IERC20Errors}}
{{IERC721Errors}}
{{IERC1155Errors}}
{{IERC1271}} {{IERC1271}}
{{IERC1363}} {{IERC1363}}

View File

@ -3,8 +3,7 @@ pragma solidity ^0.8.19;
/** /**
* @dev Standard ERC20 Errors * @dev Standard ERC20 Errors
* Interface of the ERC6093 custom errors for ERC20 tokens * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
* as defined in https://eips.ethereum.org/EIPS/eip-6093
*/ */
interface IERC20Errors { interface IERC20Errors {
/** /**
@ -50,8 +49,7 @@ interface IERC20Errors {
/** /**
* @dev Standard ERC721 Errors * @dev Standard ERC721 Errors
* Interface of the ERC6093 custom errors for ERC721 tokens * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
* as defined in https://eips.ethereum.org/EIPS/eip-6093
*/ */
interface IERC721Errors { interface IERC721Errors {
/** /**
@ -109,8 +107,7 @@ interface IERC721Errors {
/** /**
* @dev Standard ERC1155 Errors * @dev Standard ERC1155 Errors
* Interface of the ERC6093 custom errors for ERC1155 tokens * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
* as defined in https://eips.ethereum.org/EIPS/eip-6093
*/ */
interface IERC1155Errors { interface IERC1155Errors {
/** /**

View File

@ -57,6 +57,23 @@ import "@openzeppelin/{{__item_context.file.absolutePath}}";
-- --
{{/if}} {{/if}}
{{#if has-errors}}
[.contract-index]
.Errors
--
{{#each inheritance}}
{{#unless @first}}
[.contract-subindex-inherited]
.{{name}}
{{/unless}}
{{#each errors}}
* {xref-{{anchor~}} }[`++{{name}}({{names params}})++`]
{{/each}}
{{/each}}
--
{{/if}}
{{#each modifiers}} {{#each modifiers}}
[.contract-item] [.contract-item]
[[{{anchor}}]] [[{{anchor}}]]
@ -83,3 +100,12 @@ import "@openzeppelin/{{__item_context.file.absolutePath}}";
{{{natspec.dev}}} {{{natspec.dev}}}
{{/each}} {{/each}}
{{#each errors}}
[.contract-item]
[[{{anchor}}]]
==== `[.contract-item-name]#++{{name}}++#++({{typed-params params}})++` [.item-kind]#error#
{{{natspec.dev}}}
{{/each}}

View File

@ -35,6 +35,10 @@ module.exports['has-events'] = function ({ item }) {
return item.inheritance.some(c => c.events.length > 0); return item.inheritance.some(c => c.events.length > 0);
}; };
module.exports['has-errors'] = function ({ item }) {
return item.inheritance.some(c => c.errors.length > 0);
};
module.exports['inherited-functions'] = function ({ item }) { module.exports['inherited-functions'] = function ({ item }) {
const { inheritance } = item; const { inheritance } = item;
const baseFunctions = new Set(inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? []))); const baseFunctions = new Set(inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? [])));