fix(js/verify): fail clearly on non-JSON explorer responses instead of crashing#17
Open
Equious wants to merge 2 commits into
Open
fix(js/verify): fail clearly on non-JSON explorer responses instead of crashing#17Equious wants to merge 2 commits into
Equious wants to merge 2 commits into
Conversation
…f crashing `httpGet`/`httpPostForm` called `await res.json()` directly, so any non-JSON response from the explorer threw an opaque `SyntaxError: Unexpected token ...`. During an explorer outage the API returns a plaintext "no available server", which crashed the entire deploy/verify flow with no hint that the explorer was at fault. Route both helpers through `readJsonResponse`, which checks the HTTP status and guards `JSON.parse`, throwing a descriptive `BattleChainError` (status + body snippet) — mirroring the resilient handling already in `query.ts`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The vyper-json path sent the compiler version via normalizeCompilerVersion, which
just prepends "v" — so a bare "0.4.3" became "v0.4.3". The explorer's Sourcify
verifier fetches the compiler by version and needs the full "0.4.3+commit.<hash>"
with NO leading "v" (unlike solc); a bare version 404s ("Failed fetching vyper
0.4.3 for platform linux"). The Vyper fallback therefore never verified.
Add resolveVyperVersion() to derive the full X.Y.Z+commit.<hash> from the vyper
releases mirror (the same source the explorer UI uses) and use it for vyper-json;
solc keeps the "v"-prefixed full version callers already pass. Mirrors the
battlechain-lib-py fix. Latent until now — the hardhat-template verifies Solidity.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Added a second fix to this branch: |
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.
Problem
verify.ts'shttpGet/httpPostFormcallawait res.json()directly:If the explorer returns anything that isn't JSON,
res.json()throws an opaqueSyntaxError: Unexpected token 'o', "no available server" is not valid JSON,which propagates up and aborts the entire deploy/verify flow with no
indication that the explorer was at fault.
Hit live while running the
hardhat-templateflow during a brief exploreroutage — the gateway returned a plaintext
no available serverand the wholejust alldied at step 1 (MockToken verification), even though the deployitself had succeeded.
Fix
Route both helpers through a shared
readJsonResponsethat checks the HTTPstatus and guards
JSON.parse, throwing a descriptiveBattleChainError(status + a body snippet) instead of an opaque
SyntaxError. This mirrors theresilient response handling already in
query.ts(queryAgreementByContract).No API change;
build+vitest(39/39) pass.🤖 Generated with Claude Code