fix: guard address validation against non-string values - #186
Open
ayushsingh82 wants to merge 1 commit into
Open
fix: guard address validation against non-string values#186ayushsingh82 wants to merge 1 commit into
ayushsingh82 wants to merge 1 commit into
Conversation
is_valid_address() calls re.match() directly on the "address" field, which raises an uncaught TypeError if the field isn't a string (e.g. a JSON number). Because validate_token_directory() doesn't catch exceptions from validate_token_data(), a single malformed data.json aborts validation for every token in the run instead of failing just that one, with a confusing "Unexpected error" message. Every other field in validate_token_data() (name, symbol, chainId, decimals) already checks isinstance() before further validation; address and crossChainAddresses[].address did not. Add the same guard so a bad address field produces a normal "Invalid address" error scoped to that token.
ayushsingh82
requested review from
Im-Madhur-Gupta,
QEDK,
iamvukasin and
keone
as code owners
August 8, 2026 03:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_valid_address()callsre.match()directly on theaddressfield. Ifaddressindata.jsonisn't a string (e.g. a JSON number,null, or a list), this raises an uncaughtTypeError.validate_token_directory()doesn't catch exceptions fromvalidate_token_data(), so thisTypeErrorpropagates all the way up tomain()'s top-levelexcept Exception, printingUnexpected error: ...and aborting validation for every token in the run — not just the malformed one.validate_token_data()(name,symbol,chainId,decimals) already checksisinstance()before further validation. The top-leveladdressfield andcrossChainAddresses[chain_id].addressdid not follow this same pattern.isinstance(address, str)guard in both places, matching the existing style, so a badaddressfield now produces a normal, scoped"Invalid address: ..."error for that token instead of crashing the whole script.Test plan
validate_token_data({"address": 12345, ...}, ...)raisedTypeError: expected string or bytes-like objectbefore the fix."Invalid address: 12345"— no crash.crossChainAddresses[chain_id].address(e.g.{"1": {"address": 999999}}).mainnet/*/data.jsonfiles — identical results before and after (no regression on valid string addresses).uv run ruff checkanduv run ruff format --checkpass on the changed file.