tokenURI() is intended to revert with a custom ERC721Metadata__URI_QueryFor_NonExistentToken error when queried for a non-existent token ID.
The check if (ownerOf(tokenId) == address(0)) is permanently unreachable. In OpenZeppelin ERC721 (v4 and v5), ownerOf() internally calls _ownerOf() and reverts with ERC721NonexistentToken if the token does not exist — it never returns address(0). For non-existent tokens, the revert fires before the comparison is evaluated; for existing tokens, the owner can never be address(0). The custom error is dead code.
Likelihood:
The condition is unreachable on every call for every token ID — there is no code path that reaches the custom revert.
Integrators who write error-handling logic specifically for ERC721Metadata__URI_QueryFor_NonExistentToken discover it never fires during testing.
Impact:
No funds are at risk. The custom error is dead code — integrators who catch it will never see it, which can cause confusion during integration and testing.
Non-existent token queries still revert, just with OpenZeppelin's ERC721NonexistentToken instead of the custom error.
Place this test in test/ and run forge test --match-test testCustomErrorNeverEmitted. The test demonstrates that the custom NonExistentToken error in tokenURI() is unreachable because ownerOf() on a non-existent token reverts before the custom check is evaluated.
Replace ownerOf(tokenId) == address(0) with _ownerOf(tokenId) == address(0) so the internal lookup returns zero instead of reverting, allowing the custom error to fire.
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.